The place value system is the modern way in which numbers are represented. A number represented using the place value system is made up of a string of symbols separated by a dot, where each (index, symbol) combination in the string represents a value (i.e. val[idx] = compute(idx, str[idx])).
The symbols used to represent a number are called digits. All digits to the...
These wholes and fractional are combined to represent the final value for the number. For example, the number 43.5 represents...
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●● ●●● ◑
4 3 . 5
The grammar for the place value system is...
number: whole (DOT fractional)?;
whole: DIGIT+;
fractional: DIGIT+;
DOT: '.';
DIGIT: [0123456789];
The entry point to the grammar is the number rule. Note that the fractional part of the number rule is optional -- a number with a missing fractional part is assumed to have no partial value -- it consists of only entire objects.
⚠️NOTE️️️⚠️
The details below describe each sub-rule as well as the algorithm to process that sub-rule. None of the algorithms use actual numbers / number operations -- value is tracked by iteratively pushing blocks into arrays. Why create an algorithm without using numbers? Using numbers to describe numbers is circular logic.
The whole rule is used to express how many entire objects there are. The algorithm for determining that value consists of 3 steps:
Determine the value each digit represents...
0 = <empty>
1 = ●
2 = ●●
3 = ●●●
4 = ●●●●
5 = ●●●●●
6 = ●●●●●●
7 = ●●●●●●●
8 = ●●●●●●●●
9 = ●●●●●●●●●
These are the digits and their values.
Then, calculate the value for each index of the whole part. The algorithm for determining the value of each index is...
index_values = []
for (item in index) {
next_index_value = <empty>
if (index_values.isEmpty()) {
index_values.push(●)
} else {
last_index_value = index_value[-1]
for (inner_item in ●●●●●●●●●●) { // the number of dots here should be 1 more than the value of the largest symbol
next_index_value.push(last_index_value)
}
}
}
index_values.reverse()
For example, the index values in the whole part 572 are...
_ _ _
│ │ │
│ │ └─ ●
│ └─── ●●●●●●●●●●
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Now that the digit values and index values are known, the value of each (digit, index) combination can be calculated. The algorithm for determining the value of each (digit, index) combination is...
final_value = <empty>
for (digit_value, index_value) in input
value = <empty>
for item in digit_value
value.push(index_value)
For example, the (digit, index) values in the whole part 572 are....
5__
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
_7_
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
__2
●
●
Those values combined together would be...
5 7 2
│ │ │
│ │ └─ ●
│ │ ●
│ │
│ └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
The fractional rule is used to express some portion of an object (less than a single object). Conceptually, you can think of each digit in the fractional string as a recursive slicing of a single whole. For example, in the fractional string 358, the first index picks out 3 equal parts out of the whole ...
, ... the second index picks out 5 equal parts out of the NEXT part of the whole ...
, ... the third index picks out 8 equal parts out of the NEXT part of the previous part ...
.
⚠️NOTE️️️⚠️
Trouble seeing this final partition? Open the above image up standalone and zoom in. It's an SVG.
This is exactly the same as chopping up a whole into 1000 equal parts and picking 358 of those parts...
The algorithm for processing the fractional rule is similar to the conceptual model described above. It consists of 2 steps:
Determine the total number of parts there are. The algorithm for this is...
total_parts = <empty>
for (item in index) {
if (total_parts == <empty>) {
total_parts.push(●●●●●●●●●●) // the number of dots here should be 1 more than the value of the largest digit
} else {
new_total_parts = <empty>
for (inner_item in ●●●●●●●●●●) { // the number of dots here should be 1 more than the value of the largest digit
new_total_parts.push(total_parts)
}
total_parts = new_total_parts
}
}
For example, for a fractional part of 55 the total number of parts would be 100...
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
⚠️NOTE️️️⚠️
An easier way to do the same thing is...
So if the fractional string has 2 digits (as 55 does), the total number of parts would be 100.
The reason why the code above doesn't do this is because I'm trying to avoid the use of numbers and operations that haven't been introduced yet.
⚠️NOTE️️️⚠️
Know exponents? Doing 10^fractional.length is the same thing.
If the fractional string has 2 digits (as 55 does), the total number of parts would be 10^2=100.
The reason why the code above doesn't do this is because I'm trying to avoid the use of numbers and operations that haven't been introduced yet.
The fractional string is a selection out the total parts calculated in the step above.
For example, for a fractional part of 55, ...
[●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●]●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Similar to the sliced circle diagrams shown in the algorithm descriptions above, a number line may also be used to visualize the value that a number represents. It consists of a straight horizontal line with equidistant vertical notches spliced through out, where each notch is labelled with incrementally larger numbers from left-to-right...
The number being represented is marked on the line. For example, to represent the number 5...
Numbers with fractional parts may also be marked on the line. Move the marker to the whole part of the number, then determine the amount of space that the fractional part consumes and move over that much towards the next notch. For example, to represent the number 5.5...
First, move the marker over to the whole: 5...
Then, determine how much space in the fractional part was consumed. 5.5's fractional part takes up half a circle, so it gets moved half way towards the next notch...
↩PREREQUISITES↩
Equality is the concept of checking if one number to see if it has the same value as another number. In other words, checking if both numbers are the same. For example, the numbers 5 and 5 are the same number, so they're said to be equal.
If you were to visualize both numbers on a number line, they would both sit at the same position...
Equality is typically represented using the infix operator = or ==. The above example would be represented as 5=5.
The output of an equality operation is either true or false: true when the numbers are the same and false when they aren't. For example, ...
When using words, equality is typically represented using the following syntax:
⚠️NOTE️️️⚠️
Not all of the above are bookmarked because there's too much ambiguity. For example, the word "is" is used in many contexts outside of addition.
⚠️NOTE️️️⚠️
If you know algebra, the word "gives" is applicable more so to algebra and beyond. For example: the addition of x and 1 gives 5 means x+1 = 5.
The opposite of equality is not equality. That is, not equality is the concept of checking if one number has a different number of items than another number. For example, the numbers 5 and 6 are different, so they're said to be not equal.
Not equality is typically represented using the infix operator ≠ or !=. The above example would be represented as 5≠6.
The output of a not equality operation is either true or false: true when the numbers are different and false when they're the same. For example, ...
When using words, not equality is typically represented using the following syntax:
⚠️NOTE️️️⚠️
Not all of the above are bookmarked because there's too much ambiguity. For example, the words "is not" is used in many contexts outside of addition.
⚠️NOTE️️️⚠️
Sometimes you may see the word inequality. This refers to operations that compare two numbers for something other than equality: greater than (>), less than (<), not equality (≠), and potentially others.
↩PREREQUISITES↩
Greater than is the concept of checking if one number represents more items than another number. For example, the number 8 has more items than the number 5, so 8 is said to be greater than 5.
If you were to visualize both numbers on a number line, the number 8 would be ahead of 5...
Greater than is typically represented using the infix operator >. The above example would be represented as 8>5.
The output of a greater than operation is either true or false: true when the first number has more items and false when it doesn't. For example, ...
When using words, greater than is typically represented using the following syntax:
Greater than or equal is common shorthand to compare if a number is greater than or equal to some other number. It's typically represented using the infix operator ≥ or >=. For example...
When using words, greater than or equal is typically represented using the following syntax:
⚠️NOTE️️️⚠️
Think of at least as "not less than" -- 8 is not less than 5. If you can follow the logic...
↩PREREQUISITES↩
Less than is the concept of checking if one number has fewer items than another number. For example, the number 5 has fewer items than the number 8, so 5 is said to be less than 8.
If you were to visualize both numbers on a number line, the number 5 would be behind of 8...
Less than is typically represented using the infix operator <. The above example would be represented as 5<8.
The output of a less than operation is either true or false: true when the first number has fewer items and false when it doesn't. For example, ...
When using words, less than is typically represented using the following syntax:
Less than or equal is common shorthand to compare if a number is less than or equal to some other number. It's typically represented using the infix operator ≤ or <=. For example...
When using words, less than or equal is typically represented using the following syntax:
⚠️NOTE️️️⚠️
Think of at most as "not more than" -- 5 is not more than 8. If you can follow the logic...
↩PREREQUISITES↩
Addition is the concept of taking two numbers and combining their values together. For example, combining 3 items and 5 items together results in 7 items...
[●●●] [●●●●●]
3 5
group values together
[●●●●●●●●]
7
Addition is typically represented using the infix operator +. The above example would be represented as 3+5.
The output of an addition operation is called the sum. In the example above, 7 is the sum.
When using words, addition is typically represented using the following syntax:
⚠️NOTE️️️⚠️
More than, larger than, and greater than are more much more commonly used for the greater than relational operator. For example...
You'll need to disambiguate based on the context.
Properties of addition:
Order in which 2 numbers are added doesn't matter (commutative).
[●●●] [●●●●●] results in [●●●●●●●●] (3+5 is 7)
3 5 7
[●●●●●] [●●●] results in [●●●●●●●●] (5+3 is 7)
5 3 7
Any number plus 0 results in the same number (identity).
[●●●] [] results in [●●●] (3+0 is 3)
3 0 3
[] [●●●] results in [●●●] (0+3 is 3)
0 3 3
↩PREREQUISITES↩
Subtraction is the concept of removing the value of one number from another number. For example, removing 3 items from 5 items results in 2 items...
[●●●●●]
5
pick out 3 from the 5
[●●] [●●●]
2 3
Subtraction is typically represented using the infix operator -. The above example would be represented as 5-3.
The output of an subtraction operation is called the difference. In the example above, 2 is the difference.
When using words, subtraction is typically represented using the following syntax:
⚠️NOTE️️️⚠️
Fewer than, smaller than, and less than are more much more commonly used for the less than relational operator. For example...
You'll need to disambiguate based on the context.
Properties of subtraction:
Any number subtracted by 0 results in the same number (identity).
[●●●] [] results in [●●●] (3+0 is 3)
3 0 3
⚠️NOTE️️️⚠️
Unlike addition, subtraction is not commutative. 5-3 isn't the same as 3-5
↩PREREQUISITES↩
Multiplication is the concept of taking a number and iteratively adding it to itself a certain number of iterations. For example, 3 added to itself for 5 iterations results in 15 items...
3+3+3+3+3=15
[●●●] 3
[●●●] 3
[●●●] 3
[●●●] 3
[●●●] 3
Multiplication is typically represented using the infix operator *. The above example would be represented as 3*5. When written in formal math notation, it may also be written as...
⚠️NOTE️️️⚠️
Know algebra? Do not use x or a cross as a symbol for multiplication. It causes confusion for algebra expressions because x can also be a variable.
The output of a multiplication operation is called the product. In the example above, 15 is the product.
The inputs into the multiplication operation are either...
When using words, multiplication is typically represented using the following syntax:
⚠️NOTE️️️⚠️
There are certain special words that denote multiplication. For example, the word twice means 2 multiplied by something else -- e.g. twice 5 is the same thing as 2*5.
Much less common is the word thrice -- it means 3 times something else. The pattern here seems to be the add "ice" to the end of the number? Unsure, but Google seems to give a definition for fourice.
Properties of multiplication:
Order in which 2 numbers are multiplied doesn't matter (commutative).
3*5 vs 5*3
┌───┐ ┌┬┬┬┐
├●●●┤3 │●●●│
├●●●┤3 │●●●│
├●●●┤3 │●●●│
├●●●┤3 │●●●│
├●●●┤3 │●●●│
└───┘ └┴┴┴┘
555
the number of dots is the same
Any number multiplied by 0 is 0.
This makes sense if you think of multiplication as iterative addition...
var product = 0;
for (var i = 0; i < multiplicand; i++) {
product += multiplier;
}
If you iterate 0 times, the product will be 0.
Any number multiplied by 1 results in that same number (identity).
3*3=3+3+3
3*2=3+3
3*1=3 -- 3 is just by itself, it isn't being added
↩PREREQUISITES↩
Division is the concept of taking a number and iteratively subtracting it by another number to find out how many iterations it can be subtracted. For example, 15 can be subtracted by 3 exactly 5 iterations before nothing's left...
[●●●●●●●●●●●●●●●] start with 15
[●●●●●●●●●●●●] 15-3 is 12 (iteration 1)
[●●●●●●●●●] 12-3 is 9 (iteration 2)
[●●●●●●] 9-3 is 6 (iteration 3)
[●●●] 6-3 is 3 (iteration 4)
[] 3-3 is 0 (iteration 5)
Another way of thinking about division is that it's chopping up a number. Imagine cutting up a pie into 15 pieces and eating 3 pieces at a time. The pie will be done after you've eaten 5 times.
In certain cases, division may result in some remaining value that isn't large enough for another subtraction iteration to take place. This remaining value is called the remainder For example, 16 can be subtracted by 3 for 5 iterations but will have a remainder of 1...
[●●●●●●●●●●●●●●●●] start with 16
[●●●●●●●●●●●●●] 16-3 is 13 (iteration 1)
[●●●●●●●●●●] 13-3 is 10 (iteration 2)
[●●●●●●●] 10-3 is 7 (iteration 3)
[●●●●] 7-3 is 4 (iteration 4)
[●] 4-3 is 1 (iteration 5)
only 1 item left -- not enough for another subtraction iteration
1 is the remainder
Division is typically represented using the infix operator / or ÷. The above example would be represented as 15/3 or 15÷3. It may also be written as , which is just a fancier way of writing 15/3.
The output of a division operation is called the quotient. In the example above, the quotient is 5 (it subtracts 5 times).
The inputs into the division operation are called the dividend and divisor. In the example above, 15 is the dividend and 3 is the divisor.
⚠️NOTE️️️⚠️
One way to think of this is that the dividend (the number on the left / top) is the starting value, and the divisor is the number being iteratively subtracted.
When using words, division is typically represented using the following syntax:
⚠️NOTE️️️⚠️
There are certain special words that denote division. For example, the word ...
Properties of division:
Any number divided by 1 results in the same number (identity).
[●●●●●] start with 5
[●●●●] 5-1 is 4 (iteration 1)
[●●●] 4-1 is 3 (iteration 2)
[●●] 3-1 is 2 (iteration 3)
[●] 2-1 is 1 (iteration 4)
[] 1-1 is 0 (iteration 5)
5 iterations total
Any number divided by itself is 1.
[●●●●●] start with 5
[] 5-5 is 0 (iteration 1)
1 iteration total
Any number divided by 0 is infinity.
This makes sense if you think of division as iterative subtraction...
var quotient = 0;
while (dividend >= divisor) {
dividend -= divisor;
quotient += 1;
}
This will iterate forever if the divisor is 0 because the dividend would never become less than the divisor -- the loop wouldn't terminate.
⚠️NOTE️️️⚠️
Another way to think of this is that division is the inverse of multiplication (it undoes multiplication). If it were the case that 10/0=?, then ?*0=10. We know that this can't be the case because ?*0=0.
↩PREREQUISITES↩
Whole numbers are numbers which have no fractional part -- they only consist of wholes. For example, 5, 0, 104, and 27 are whole numbers while 4.2 is not.
The difference between whole numbers and natural / counting / cardinal numbers is that counting numbers don't include 0 (they start at 1). That is, counting numbers start where you start counting / where something exists. For example, if you're counting apples, you start counting at 1 -- there needs to be at least 1 apple to start.
↩PREREQUISITES↩
The algorithm used by humans to test for whole number equality relies on two idea...
If two whole numbers are equal then they must have the same number of digits. For example, 55 and 9123456 aren't equal because the number of digits between them isn't the same -- 55 has 2 digits while 9123456 has 7 digits.
Numbers represented in place-value notation can be broken down into single digit components -- the place of each digit in the number represents some portion of that number's value. For example, the number 935 can be broken down as 9 100s, 3 10s, and 5 1s...
100
100
100
100
100 1
100 1
100 10 1
100 10 1
100 10 1
--- -- -
900 30 5
9 3 5
│ │ │
│ │ └─ ●
│ │ ●
│ │ ●
│ │ ●
│ │ ●
│ │
│ └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Since the numbers being tested for equality must have the same number of digits between them, the first test to see if they may be equal is to a ensure that the number of digits are equal (idea 1). For example, 55 has 2 digits while 9123456 has 7 digits -- there's no point in going any further because if the number of digits aren't the same then there's no way for the actual numbers to be the same.
If it turns out that the number of digits are the same, then each place's digit is tested for equality (idea 2). If all the digits are equal, then the numbers are equal. For example, the numbers 195 and 195 are equal...
1 9 5
| | |
1 9 5
... while the numbers 175 and 195 are not equal...
1 7 5
| x |
1 9 5
The way to perform this algorithm via code is as follows...
@log_decorator
def __eq__(lhs: WholeNumber, rhs: WholeNumber) -> bool:
if isinstance(rhs, int):
rhs = WholeNumber.from_int(rhs)
elif isinstance(rhs, str):
rhs = WholeNumber.from_str(rhs)
if not isinstance(rhs, WholeNumber):
raise Exception()
log(f'Equality testing {lhs} and {rhs}...')
log_indent()
ret = lhs.digits == rhs.digits
log_unindent()
log(f'{ret}')
return ret⚠️NOTE️️️⚠️
The code is making use of python lists to do the 2 tests above. Python's list equality already applies ideas 1 and 2 internally to determine if the contents of the list are equal.
↩PREREQUISITES↩
The algorithm used by humans to test for whole number less than relies on the idea that numbers represented in place-value notation can be broken down into single digit components -- the place of each digit in the number represents some portion of that number's value. For example, the number 935 can be broken down as 9 100s, 3 10s, and 5 1s...
100
100
100
100
100 1
100 1
100 10 1
100 10 1
100 10 1
--- -- -
900 30 5
9 3 5
│ │ │
│ │ └─ ●
│ │ ●
│ │ ●
│ │ ●
│ │ ●
│ │
│ └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Since a number can be broken down into single digit components, each single digit component from the numbers being compared can individually tested from most significant to least significant (left-to-right). If a digit from the number being tested is...
If no more digits are remaining for testing, the number being tested is equal.
For example, imagine testing the number 23 and 21...
2 3 2 1
│ │ │ │
│ └─ ● │ └─ ●
│ ● │
│ ● └─── ●●●●●●●●●●
│ ●●●●●●●●●●
└─── ●●●●●●●●●●
●●●●●●●●●●
The first digits are equal (2 == 2), so move to the next digit. The next digit is larger than the other digit (3 > 1), so 23 is not less than 21.
⚠️NOTE️️️⚠️
What happens when the number of digits aren't the same between the numbers being tested (e.g. 55 and 12345)? Recall how place-value notation works. 0 can be used when a corresponding digit doesn't exist at some position.
The way to perform this algorithm via code is as follows...
@log_decorator
def __lt__(lhs: WholeNumber, rhs: WholeNumber) -> bool:
if isinstance(rhs, int):
rhs = WholeNumber.from_int(rhs)
elif isinstance(rhs, str):
rhs = WholeNumber.from_str(rhs)
if not isinstance(rhs, WholeNumber):
raise Exception()
log(f'Less than testing {lhs} and {rhs}...')
log_indent()
count = max(len(lhs.digits), len(rhs.digits))
for pos in reversed(range(0, count)): # from smallest to largest component
log(f'Test digits {lhs[pos]} and {rhs[pos]}...')
if lhs[pos] > rhs[pos]:
log(f'{lhs[pos]} > {rhs[pos]} -- {lhs} is NOT less than {rhs}, it is greater than')
return False
elif lhs[pos] < rhs[pos]:
log(f'{lhs[pos]} < {rhs[pos]} -- {lhs} is less than {rhs}')
return True
else:
log(f'{lhs[pos]} == {rhs[pos]} -- continuing testing')
log(f'No more digits to test -- {lhs} is NOT less than {rhs}, it is equal')
return False↩PREREQUISITES↩
The algorithm used by humans to test for whole number greater than relies on the idea that numbers represented in place-value notation can be broken down into single digit components -- the place of each digit in the number represents some portion of that number's value. For example, the number 935 can be broken down as 9 100s, 3 10s, and 5 1s...
100
100
100
100
100 1
100 1
100 10 1
100 10 1
100 10 1
--- -- -
900 30 5
9 3 5
│ │ │
│ │ └─ ●
│ │ ●
│ │ ●
│ │ ●
│ │ ●
│ │
│ └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Since a number can be broken down into single digit components, each single digit component from the numbers being compared can individually tested from most significant to least significant (left-to-right). If a digit from the number being tested is...
If no more digits are remaining for testing, the number being tested is equal.
For example, imagine testing the number 23 and 21...
2 3 2 1
│ │ │ │
│ └─ ● │ └─ ●
│ ● │
│ ● └─── ●●●●●●●●●●
│ ●●●●●●●●●●
└─── ●●●●●●●●●●
●●●●●●●●●●
The first digits are equal (2 == 2), so move to the next digit. The next digit is larger than the other digit (3 > 1), so 23 is greater than than 21.
⚠️NOTE️️️⚠️
What happens when the number of digits aren't the same between the numbers being tested (e.g. 55 and 12345)? Recall how place-value notation works. 0 can be used when a corresponding digit doesn't exist at some position.
The way to perform this algorithm via code is as follows...
@log_decorator
def __gt__(lhs: WholeNumber, rhs: WholeNumber) -> bool:
if isinstance(rhs, int):
rhs = WholeNumber.from_int(rhs)
elif isinstance(rhs, str):
rhs = WholeNumber.from_str(rhs)
if not isinstance(rhs, WholeNumber):
raise Exception()
log(f'Greater than testing {lhs} and {rhs}...')
log_indent()
count = max(len(lhs.digits), len(rhs.digits))
for pos in reversed(range(0, count)): # from smallest to largest component
log(f'Test digits {lhs[pos]} and {rhs[pos]}...')
if lhs[pos] > rhs[pos]:
log(f'{lhs[pos]} > {rhs[pos]} -- {lhs} is greater than {rhs}')
return True
elif lhs[pos] < rhs[pos]:
log(f'{lhs[pos]} < {rhs[pos]} -- {lhs} is NOT greater than {rhs}, it is less than')
return False
else:
log(f'{lhs[pos]} == {rhs[pos]} -- continuing testing')
log(f'No more digits to test -- {lhs} is NOT greater than {rhs}, it is equal')
return False↩PREREQUISITES↩
The algorithm used by humans to add large whole numbers together is called vertical addition. Vertical addition relies on two ideas...
Humans can easily add a single digit number to another single digit number without much effort. For example...
... are all addition operations that don't take much effort / are already probably cached in person's memory.
Numbers represented in place-value notation can be broken down into single digit components -- the place of each digit in the number represents some portion of that number's value. For example, the number 935 can be broken down as 9 100s, 3 10s, and 5 1s...
100
100
100
100
100 1
100 1
100 10 1
100 10 1
100 10 1
--- -- -
900 30 5
9 3 5
│ │ │
│ │ └─ ●
│ │ ●
│ │ ●
│ │ ●
│ │ ●
│ │
│ └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Since a number can be broken down into single digit components and adding a single digit to any number is easy, any two numbers can be added by adding their individual single digit components. For example, the number 53 and 21 are broken down as follows...
5 3 2 1
│ │ │ │
│ └─ ● │ └─ ●
│ ● │
│ ● └─── ●●●●●●●●●●
│ ●●●●●●●●●●
└─── ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
Add their individual single digit components together to get the sum. The ...
7 4
│ │
│ └─ ●
│ ●
│ ●
│ ●
│
└─── ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
In certain cases, the addition of two single digit components may bleed over to the next single digit component. For example, adding 93 and 21 can be broken down as follows...
Combining the 10s place resulted in a bleed over to the hundreds place. This extra 100s place bleed over digit can be carried over and combined into the hundreds place. This process is called carry-over -- you're carrying-over the extra bleed over digit to its correct place and combining it with whatever else is there.
Conceptually, carrying-over is the idea of breaking out a group of 10 from the current place and moving them over to the next highest place (e.g. 10s place to 100s place). For example, when adding 93 to 21, adding the digits at the 10's place (90+20) results in 110...
9 3 2 1
│ │ │ │
│ └─ ● │ └─ ●
│ ● │
│ ● └─── ●●●●●●●●●●
│ ●●●●●●●●●●
└─── ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
results in
11 4
│ │
│ └─ ●
│ ●
│ ●
│ ●
│
└─── ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
Since 11 is too many digits for the tens place (each place must only have 1 digit), break out 10 groups from the 10s place and move those over to the 100s place...
11 4
│ │
│ └─ ●
│ ●
│ ●
│ ●
│
└─── ●●●●●●●●●●
┌──────────┐
│●●●●●●●●●●│
│●●●●●●●●●●│ each group is 10 items and we grabbed 10 of them (that's 100 items total)
│●●●●●●●●●●│
│●●●●●●●●●●│
│●●●●●●●●●●│
│●●●●●●●●●●│
│●●●●●●●●●●│
│●●●●●●●●●●│
│●●●●●●●●●●│
│●●●●●●●●●●│
└──────────┘
move those 100 items as 1 group of 100s
1 1 4
│ │ │
│ │ └─ ●
│ │ ●
│ │ ●
│ │ ●
│ │
│ └─── ●●●●●●●●●●
│ ┌────────────────────────────────────────────────────────────────────────────────────────────────────┐
└─────│●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●│
└────────────────────────────────────────────────────────────────────────────────────────────────────┘
The digit in the 10s place is the result for the 10s place, while the digit in the 100s place gets combined in with the 100s place. In the above example, the 100s place was empty, so the carry-over remained as-is.
The way to perform this algorithm in real-life is to stack the two numbers being added on top of each other, where the positions for both numbers match up (e.g. the 1s position matches up, the 10s position matches up, the 100s position matched up, etc..). Then, add the individual single digit components together (from right-to-left). For example...
⚠️NOTE️️️⚠️
The number 21 has nothing in its 100s place -- nothing is the same as 0. 21 is the same as 021.
If 2 individual single digit components combine together to results in an extra digit (e.g. 5+8=13), the bleed over digit is carried over to the next position (on the left). This is denoted by stacking the bleed over digit on top of the next position -- it's being combined along with the other digits at that position. For example...
The way to perform this algorithm via code is as follows...
@log_decorator
def __add__(lhs: WholeNumber, rhs: WholeNumber) -> WholeNumber:
log(f'Adding {lhs} and {rhs}...')
log_indent()
cache = [
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
[3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
[4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
[6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
[7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
[8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
[9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
]
count = max(len(lhs.digits), len(rhs.digits))
carryover_digit = None
result = WholeNumber.from_int(0)
for pos in range(0, count): # from smallest to largest component
log(f'Targeting {lhs._highlight(pos)} and {rhs._highlight(pos)}')
log_indent()
digit1 = lhs[pos]
digit2 = rhs[pos]
added = WholeNumber.from_int(cache[digit1.value][digit2.value])
log(f'Using cache for initial add: {digit1} + {digit2} = {added}')
if carryover_digit is not None:
log(f'Using recursion for carryover add: {added} + {carryover_digit} = ...')
added = added + WholeNumber.from_digit(carryover_digit) # recurse -- this called __add__()
carryover_digit = None
if len(added) == 1:
result[pos] = added[0]
elif len(added) == 2:
result[pos] = added[0] # keep 1s digit
carryover_digit = added[1] # carryover 10s digit
else:
raise Exception('This should never happen')
log(f'Result: {result._highlight(pos)}, Carryover: {carryover_digit}')
log_unindent()
if carryover_digit is not None:
log(f'Remaining carryover: {lhs._highlight(count)} [{carryover_digit}]')
result[count] = carryover_digit
log(f'Result: {result._highlight(count)}')
log_unindent()
log(f'Sum: {result}')
return result↩PREREQUISITES↩
The algorithm used by humans to subtract large whole numbers from each other is called vertical subtraction. Vertical subtraction relies on two ideas...
Humans can easily subtract a small 1 to 2 digit numbers (anything smaller than 20) from each other without much effort. For example...
... are all subtraction operations that don't take much effort / are already probably cached in person's memory.
Numbers represented in place-value notation can be broken down into single digit components -- the place of each digit in the number represents some portion of that number's value. For example, the number 935 can be broken down as 9 100s, 3 10s, and 5 1s...
100
100
100
100
100 1
100 1
100 10 1
100 10 1
100 10 1
--- -- -
900 30 5
9 3 5
│ │ │
│ │ └─ ●
│ │ ●
│ │ ●
│ │ ●
│ │ ●
│ │
│ └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Since a number can be broken down into single digit components and subtracting a single digit to any number is easy, any two numbers can be subtracted by subtracting their individual single digit components. For example, the number 53 and 21 are broken down as follows...
5 3 2 1
│ │ │ │
│ └─ ● │ └─ ●
│ ● │
│ ● └─── ●●●●●●●●●●
│ ●●●●●●●●●●
└─── ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
Subtract their individual single digit components from each other to get the difference. The ...
3 2
│ │
│ └─ ●
│ ●
│
└─── ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
In certain cases, the subtraction of two single digit components may not be possible. For example, subtracting 91 and 23...
9 1 2 3
│ │ │ │
│ └─ ● │ └─ ●
│ │ ●
└─── ●●●●●●●●●● │ ●
●●●●●●●●●● │
●●●●●●●●●● └─── ●●●●●●●●●●
●●●●●●●●●● ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
The ...
The algorithm fails at the 1s place. It's impossible to remove 3 items from 1 item -- the most that can be removed from 1 item is 1 item. The way to handle this is to pick out 1 group from the 10s place and mover it over back to 1s place...
9 1 2 3
│ │ │ │
│ └─ ● │ └─ ●
│ │ ●
└─── ●●●●●●●●●● │ ●
●●●●●●●●●● │
●●●●●●●●●● └─── ●●●●●●●●●●
●●●●●●●●●● ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
┌──────────┐
│●●●●●●●●●●│ each group is 10 items and we grabbed 1 of them (that's 10 items total)
└──────────┘
move those items back to the 1s place
8 11 2 3
│ │ │ │
│ └─ ● │ └─ ●
| ┌─┐ │ ●
│ │●│ │ ●
│ │●│ │
│ │●│ └─── ●●●●●●●●●●
│ │●│ ●●●●●●●●●●
│ │●│
│ │●│
│ │●│
│ │●│
│ │●│
│ │●│
│ └─┘
│
└─── ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
Now it's possible to subtract. The ...
This process is called borrowing -- you're borrowing 1 group from the next largest position and moving those items back so that there's enough for subtraction to take place. In total, the value is still the same -- the total number of items (dots) doesn't change, but the items are being moved around so that the subtraction of a component can happen.
In certain cases, a group may need to be borrowed but the next largest position is 0. For example, subtracting 100 and 11...
1 0 0 1 1
│ │ │ │ │
│ │ └─ ● │ └─ ●
│ │ │
│ └─── <empty> └─── ●●●●●●●●●●
│
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Borrow recursively to handle this case:
subtract 1s position: 0-1 not possible, borrow from 10s position
borrow from 10s position: can't borrow 10s position is 0, borrow from 100s position
borrow from 100s position: 100s position changes from 1 to 0
1 0 0 1 1
│ │ │ │ │
│ │ └─ ● │ └─ ●
│ │ │
│ └─── <empty> └─── ●●●●●●●●●●
│ ┌────────────────────────────────────────────────────────────────────────────────────────────────────┐
└─────│●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●│
└────────────────────────────────────────────────────────────────────────────────────────────────────┘
move those items back to the 10s place (1 group in 100s becomes 10 groups in the 10s)
0 10 0 1 1
│ │ │ │ │
│ │ └─ ● │ └─ ●
│ │ │
│ └───┌──────────┐ └─── ●●●●●●●●●●
│ │●●●●●●●●●●│
│ │●●●●●●●●●●│
│ │●●●●●●●●●●│
│ │●●●●●●●●●●│
│ │●●●●●●●●●●│
│ │●●●●●●●●●●│
│ │●●●●●●●●●●│
│ │●●●●●●●●●●│
│ │●●●●●●●●●●│
│ │●●●●●●●●●●│
│ └──────────┘
│
└───── <empty>
borrow from 10s position: 10s position changes from 10 to 9
0 10 0 1 1
│ │ │ │ │
│ │ └─ ● │ └─ ●
│ │ │
│ └─── ●●●●●●●●●● └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ┌──────────┐
| │●●●●●●●●●●│
│ └──────────┘
│
└───── <empty>
move those items back to the 1s place (1 group in 10s becomes 10 items in the 1s)
0 9 10 1 1
│ │ │ │ │
│ │ └─┌─┐ │ └─ ●
│ │ │●│ │
│ │ │●│ └─── ●●●●●●●●●●
│ │ │●│
│ │ │●│
│ │ │●│
│ │ │●│
│ │ │●│
│ │ │●│
│ │ │●│
│ │ │●│
│ │ └─┘
│ └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│
└───── <empty>
subtract 1s position: 10-1 results in 9
subtract 10s position: 9-1 results in 8
subtract 100s position: 0-0 results in 0 (why? because 11 is the same as 011)
The way to perform this algorithm in real-life is to stack the two numbers being subtracted on top of each other, where the positions for both numbers match up (e.g. the 1s position matches up, the 10s position matches up, the 100s position matched up, etc..). Then, subtract the individual single digit components together (from right-to-left). Everytime borrowing is needed, cross out the number being changed and put the place their new numbers above. For example, subtracting 100 and 11 ...
subtract 1s position: 0-1 not possible, borrow from 10s position
subtract 1s position: 10-1 results in 9
subtract 10s position: 9-1 results in 8
subtract 100s position: 0-0 results in 0
⚠️NOTE️️️⚠️
The number 11 has nothing in its 100s place -- nothing is the same as 0. 11 is the same as 011.
The way to perform this algorithm via code is as follows...
@log_decorator
def __sub__(lhs: WholeNumber, rhs: WholeNumber) -> WholeNumber:
log(f'Subtracting {lhs} and {rhs}...')
log_indent()
sub_cache = [
[0, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None],
[1, 0, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None],
[2, 1, 0, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None],
[3, 2, 1, 0, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None],
[4, 3, 2, 1, 0, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None],
[5, 4, 3, 2, 1, 0, None, None, None, None, None, None, None, None, None, None, None, None, None, None],
[6, 5, 4, 3, 2, 1, 0, None, None, None, None, None, None, None, None, None, None, None, None, None],
[7, 6, 5, 4, 3, 2, 1, 0, None, None, None, None, None, None, None, None, None, None, None, None],
[8, 7, 6, 5, 4, 3, 2, 1, 0, None, None, None, None, None, None, None, None, None, None, None],
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None, None, None, None, None, None, None, None, None, None],
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None, None, None, None, None, None, None, None, None],
[11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None, None, None, None, None, None, None, None],
[12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None, None, None, None, None, None, None],
[13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None, None, None, None, None, None],
[14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None, None, None, None, None],
[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None, None, None, None],
[16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None, None, None],
[17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None, None],
[18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, None],
[19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ]
]
# copy self because it may get modified during borrowing phase
self_copy = lhs.copy()
count = max(len(self_copy.digits), len(rhs.digits))
result = WholeNumber.from_int(0)
for pos in range(0, count): # from smallest to largest component
log(f'Targeting {self_copy._highlight(pos)} and {rhs._highlight(pos)}')
log_indent()
digit1 = self_copy[pos]
digit2 = rhs[pos]
result_digit = sub_cache[digit1.value][digit2.value]
if result_digit is not None:
log(f'Using cache for subtraction: {digit1} - {digit2} = {result_digit}')
else:
log('Not possible -- attempting to borrow')
self_copy._borrow_from_next(sub_cache, pos)
digit1 = self_copy[pos]
digit2 = rhs[pos]
result_digit = sub_cache[digit1.value][digit2.value]
log(f'Using cache for subtraction: {digit1} - {digit2} = {result_digit}')
result[pos] = result_digit
log(f'Result: {result._highlight(pos)}')
log_unindent()
log_unindent()
log(f'Difference: {result}')
return result
@log_decorator
def _borrow_from_next(self: WholeNumber, sub_cache: List[List[int]], pos: int) -> None:
if pos >= len(self):
raise Exception('Not enough available to borrow')
curr_digit = self[pos]
next_digit = self[pos + 1]
log(f'Borrowing from next largest {self._highlight(pos + 1)}')
if next_digit == 0:
log(f'Not possible -- attempting to borrow again')
self._borrow_from_next(sub_cache, pos + 1) # recursively borrow
next_digit = self[pos + 1] # updated because of borrow call above
next_digit = sub_cache[next_digit.value][1] # sub 1 from next largest position
curr_digit = (WholeNumber.from_int(10) + WholeNumber.from_digit(curr_digit))._as_digit() # add 10 to current position
# curr_digit is no longer an actual digit -- it's beyond the value of 9 (a digit is 0..9). We're using a
# hack to get a out-of-bounds value as a digit because we need to subtract from it later on -- this is
# trying to faithfully replicate the 'borrowing' logic in vertical subtraction
self[pos + 1] = next_digit
self[pos] = curr_digit
log(f'Completed borrowing {self._highlight(pos, pos + 1)}')↩PREREQUISITES↩
The algorithm used by humans to multiply large whole numbers together is called vertical multiplication. Vertical multiplication relies on three ideas...
Humans have the ability to multiply a single digit number to another single digit number through memorization. For example...
... are all multiplication operations that can be done quickly if the person has cached the table below into their memory.
| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 2 | 0 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 |
| 3 | 0 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 |
| 4 | 0 | 4 | 8 | 12 | 15 | 20 | 24 | 28 | 32 | 36 |
| 5 | 0 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 |
| 6 | 0 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 |
| 7 | 0 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 |
| 8 | 0 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 |
| 9 | 0 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 |
Numbers represented in place-value notation can be broken down into single digit components -- the place of each digit in the number represents some portion of that number's value. For example, the number 935 can be broken down as 9 100s, 3 10s, and 5 1s...
100
100
100
100
100 1
100 1
100 10 1
100 10 1
100 10 1
--- -- -
900 30 5
9 3 5
│ │ │
│ │ └─ ●
│ │ ●
│ │ ●
│ │ ●
│ │ ●
│ │
│ └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
If two numbers start with a single non-zero digit is followed by zero or more 0s, the result of their multiplication is equivalent to multiplying the single non-zero digits together and appending the 0s to the end. For example, ..
30 * 2 is 60 -- 3 ends in 1 zero and 2 ends in no zeros, so the result has 1 zero
┌─┬─┬─┐
│●│●│●│
├─┼─┼─┤ 3*2, each box has 1 item and there's 6 boxes -- 6 total items
│●│●│●│
└─┴─┴─┘
┌──────────┬──────────┬──────────┐
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
├──────────┼──────────┼──────────┤ 30*2, each box has 10 items and there's 6 boxes -- 60 total items
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
└──────────┴──────────┴──────────┘
3 * 20 is 60 -- 3 ends in no zeros and 2 ends in 1 zero, so the result has 1 zero
┌─┬─┬─┐
│●│●│●│
├─┼─┼─┤ 3*2, each box has 1 item and there's 6 boxes -- 6 total items
│●│●│●│
└─┴─┴─┘
┌─┬─┬─┐
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
├─┼─┼─┤ 3 * 20, each box has 10 items and there's 6 boxes -- 60 total items
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
│●│●│●│
└─┴─┴─┘
30 * 20 is 600 -- 30 ends in 1 zero and 20 ends in 1 zero, so the result has 2 zeros
┌─┬─┬─┐
│●│●│●│
├─┼─┼─┤ 3*2, each box has 1 item and there's 6 boxes -- 6 total items
│●│●│●│
└─┴─┴─┘
┌──────────┬──────────┬──────────┐
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
├──────────┼──────────┼──────────┤ 30 * 20, box has 100 items and there's 6 boxes -- 600 total items
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
│●●●●●●●●●●│●●●●●●●●●●│●●●●●●●●●●│
└──────────┴──────────┴──────────┘
Any two numbers can be multiplied by ...
For example, the number 43 and 2 are broken down as follows...
4 3 2
│ │ │
│ └─ ● └─ ●
│ ● ●
│ ●
│
└─── ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
Multiply their individual single digit components together results in ...
Add the results of the multiplications: 80 + 6 is 86. Note that 43 + 43 is also 86. Each multiplication above is giving back a portion of the final multiplication value, specifically a portion of a single digit component in the final multiplication value -- they need to be combined by adding.
8 6
│ │ ┌─┐
│ └─┤●│
│ │●│ 3
│ │●│
│ ├─┤
│ │●│
│ │●│ 3
│ │●│
│ └─┘
│ ┌──────────┐
└───┤●●●●●●●●●●│
│●●●●●●●●●●│
│●●●●●●●●●●│ 4
│●●●●●●●●●●│
├──────────┤
│●●●●●●●●●●│
│●●●●●●●●●●│
│●●●●●●●●●●│ 4
│●●●●●●●●●●│
└──────────┘
For another more complex example, the number 43 and 22 are broken down as follows...
4 3 2 2
│ │ │ │
│ └─ ● │ └─ ●
│ ● │ ●
│ ● │
│ └─── ●●●●●●●●●●
└─── ●●●●●●●●●● ●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
●●●●●●●●●●
Multiply their individual single digit components together results in ...
Add the results of the multiplications: 800 + 60 + 80 + 6 is 946. Note that 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 + 43 is also 946. Each multiplication above is giving back a portion of the final multiplication value, specifically a portion of a single digit component in the final multiplication value -- they need to be combined by adding.
The way to perform this algorithm in real-life is to stack the two numbers being multiplied on top of each other, where the positions for both numbers match up (e.g. the 1s position matches up, the 10s position matches up, the 100s position matched up, etc..). For example...
Then, for each component in the bottom number (from right-to-left), isolate to its single digit component and multiply by each component in the top number (from right-to-left). The answer for each digit of the bottom row is written underneath the answer prior to it. Starting from the first component of the bottom number...
Isolate to 2 (bottom) and 3 (top), resulting in 6.
Isolate to 2 (bottom) and 40 (top), resulting in 80. Only the 8 needs to be written because this is effectively the same as doing 40*2 (80) then adding the 6 from the 3*2 prior -- 80+6 is 86.
Isolate to 20 (bottom) and 3 (top), resulting in 60.
Isolate to 20 (bottom) and 40 (top), resulting in 800. Only the 8 needs to be written because this is effectively the same as doing 40*20 (800) then adding the 60 from the 3*20 prior -- 800+60 is 860.
Then, add the answers from each bottom iteration to get the final answer...
In many cases, multiplying 2 individual single digit components results in an extra digit (e.g. 7*7=49). If this happens, the bleed over digit is carried over to the next position (on the left). That is, the bleed over digit will get added to the result of the multiplication in the next position. This is denoted by stacking the bleed over digit on top of the next position. For example...
Isolate to 7 (bottom) and 7 (top), resulting in 49. The 9 is kept and 40 carries over to the next position.
Isolate to 7 (bottom) and 70 (top), resulting in 490. Add the 40 from the carry-over to make it 530. Only the 53 needs to be written because this is effectively the same as having 530 then adding the 9 from the 7*7 prior -- 530+9 is 539.
Isolate to 80 (bottom) and 7 (top), resulting in 560. The 60 is kept and 500 carries over to the next position.
Isolate to 80 (bottom) and 70 (top), resulting in 5600. Add the 500 from the carry-over to make it 6100. Only the 61 needs to be written because this is effectively the same as having 6100 then adding the 60 from the 80*7 prior -- 6100+60 is 6160.
Then, add the answers from each bottom iteration to get the final answer...
The way to perform this algorithm via code is as follows...
@log_decorator
def __mul__(lhs: WholeNumber, rhs: WholeNumber) -> WholeNumber:
log(f'Multiplying {lhs} and {rhs}...')
log_indent()
count = len(rhs.digits)
res_list = []
for pos in range(0, count): # from smallest to largest component
log(f'Targeting {lhs} and {rhs._highlight(pos)}')
log_indent()
self_copy = lhs.copy() # create a copy
self_copy.shift_left(pos) # shift copy (add 0s) based on the digit we're on
log(f'Appending 0s to multiplicand based on position of multiplier (pos {pos}): {self_copy} {rhs._highlight(pos)}')
res = self_copy._single_digit_mul(rhs[pos]) # multiply copy by that digit
log_unindent()
res_list.append(res)
log(f'Summing intermediate results to get final result...')
log_indent()
final_res = WholeNumber.from_int(0)
for res in res_list:
log(f'Adding {res} to {final_res}')
final_res += res
log_unindent()
log_unindent()
log(f'Product: {final_res}')
return final_res
@log_decorator
def _single_digit_mul(self: WholeNumber, digit: Digit) -> WholeNumber:
cache = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18],
[0, 3, 6, 9, 12, 15, 18, 21, 24, 27],
[0, 4, 8, 12, 16, 20, 24, 28, 32, 36],
[0, 5, 10, 15, 20, 25, 30, 35, 40, 45],
[0, 6, 12, 18, 24, 30, 36, 42, 48, 54],
[0, 7, 14, 21, 28, 35, 42, 49, 56, 63],
[0, 8, 16, 24, 32, 40, 48, 56, 64, 72],
[0, 9, 18, 27, 36, 45, 54, 63, 72, 81]
]
count = len(self.digits)
carryover_digit = None
result = WholeNumber.from_int(0)
for pos in range(0, count): # from smallest to largest component
log(f'Targeting {self._highlight(pos)} and {digit}')
log_indent()
digit1 = self[pos]
multed = WholeNumber.from_int(cache[digit1.value][digit.value])
log(f'Using cache for initial mul: {digit1} * {digit} = {multed}')
if carryover_digit is not None:
adjusted_multed = multed + WholeNumber.from_digit(carryover_digit)
log(f'Adding carryover: {multed} + {carryover_digit} = {adjusted_multed}')
carryover_digit = None
multed = adjusted_multed
if len(multed) == 1:
result[pos] = multed[0]
elif len(multed) == 2:
result[pos] = multed[0] # keep 1s digit
carryover_digit = multed[1] # carryover 10s digit
else:
raise Exception('This should never happen')
log(f'Result: {result._highlight(pos)}, Carryover: {carryover_digit}')
log_unindent()
if carryover_digit is not None:
log(f'Remaining carryover: {self._highlight(count)} [{carryover_digit}]')
result[count] = carryover_digit
log(f'Result: {result._highlight(count)}')
return result↩PREREQUISITES↩
There are 2 algorithms used to divide large whole numbers:
These algorithms are detailed in the subsections below.
↩PREREQUISITES↩
Trial-and-error division is an algorithm used for dividing numbers. The core idea behind the algorithm is that multiplication is the inverse of division. That is, multiplication reverses / un-does division (and vice-versa). For example...
Knowing this, multiplication can be used to check if some number is the quotient. For example, to find the quotient for 20 / 5...
5 * 4 is 20 -- If you have 5 groups of 4 items each, you'll have 20 items.
Rather than testing each number one-by-one, it's faster to start with a number range and narrow / tweak it until you converge to the answer. That is, start with an arbitrary lower-bound and upper-bound and test both. If the product is...
Repeat until the answer is found.
For example, 2617 / 52...
Decide on a range and test...
2617 sits BETWEEN the range, so narrow...
2617 sits BELOW the range, so move up...
2617 sits between the range, so narrow...
2617 sits between the range but doesn't make sense to narrow any further. The quotient is 50, the remainder is 17 (2617 - 2600).
⚠️NOTE️️️⚠️
There's a specific algorithm for picking a starting range as well as how much to tweak that range in each iteration. You'll find those algorithms if you view the file for the code below (they aren't shown in the output).
If you're doing this on paper you can just look and guess. If you're writing code you should probably use these algorithms or come up with something better.
The trial-and-error division algorithm written as code is as follows:
@staticmethod
@log_decorator
def trial_and_error_div(dividend: WholeNumber, divisor: WholeNumber) -> (WholeNumber, WholeNumber):
if divisor == WholeNumber.from_int(0):
raise Exception('Cannot divide by 0')
log(f'Dividing {dividend} by {divisor}...')
log_indent()
if dividend == 0:
log(f'Found: {dividend} / {divisor} = 0R0')
return WholeNumber.from_int(0), WholeNumber.from_int(0)
wn_range = WholeNumber.pick_start_range(dividend)
log(f'Start range: [{wn_range.min}, {wn_range.max}]')
quotient = None
remainder = None
while True:
min_test = divisor * wn_range.min
max_test = divisor * wn_range.max
log_indent()
log(f'{divisor} * {wn_range.min} = {min_test}')
log(f'{divisor} * {wn_range.max} = {max_test}')
log_unindent()
# check if found
if min_test == dividend: # found as min
quotient = wn_range.min
remainder = WholeNumber.from_int(0)
break
if max_test == dividend: # found as max
quotient = wn_range.max
remainder = WholeNumber.from_int(0)
break
if min_test < dividend < max_test and wn_range.max - wn_range.min == 1: # found between min and max
quotient = wn_range.min
remainder = dividend - min_test
break
# not found, so modify range
if min_test < dividend < max_test:
WholeNumber.narrow_range(dividend, divisor, wn_range)
log(f'Narrowing range: [{wn_range.min}, {wn_range.max}]')
elif min_test < dividend and max_test < dividend:
WholeNumber.move_up_range(wn_range)
log(f'Increasing range: [{wn_range.min}, {wn_range.max}]')
elif min_test > dividend and max_test > dividend:
WholeNumber.move_down_range(wn_range)
log(f'Decreasing range: [{wn_range.min}, {wn_range.max}]')
log_unindent()
log(f'Quotient: {quotient}, Remainder: {remainder}')
return quotient, remainder↩PREREQUISITES↩
The algorithm used by humans to divide large whole numbers is called long division. In most cases, it can divide a number in less steps than trial-and-error division. Long division relies on three ideas...
Numbers represented in place-value notation can be broken down into single digit components -- the place of each digit in the number represents some portion of that number's value. For example, the number 935 can be broken down as 9 100s, 3 10s, and 5 1s...
100
100
100
100
100 1
100 1
100 10 1
100 10 1
100 10 1
--- -- -
900 30 5
9 3 5
│ │ │
│ │ └─ ●
│ │ ●
│ │ ●
│ │ ●
│ │ ●
│ │
│ └─── ●●●●●●●●●●
│ ●●●●●●●●●●
│ ●●●●●●●●●●
│
└───── ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
Any number can be divided using trial-and-error division. For example, 20 / 5...
When dividing, if the number being divided (dividend) has trailing zeros, those trailing zeros can be removed prior to the division and then put back on after the division. For example, 4500 / 6...
When 4500 items are broken up into groups of 6, this rule says that there will be at least 700 groups. 300 of the 4500 items remain unaccounted for, but the rule can be used again on these 300 items because 300 has trailing 0s (recursive).
⚠️NOTE️️️⚠️
It's easy to test if this is correct...
⚠️NOTE️️️⚠️
The reasoning behind why trailing 0s can be removed and re-appended has to do with expressions / order of operations / factoring. Taking the original 4500 / 7 example above...
In certain cases, the quotient returned by the operation will end up being 0. This means that the operation failed.
If this happens, less trialing-zeros need to be stripped-off. Keep leaving in trialing 0s and re-doing the operation until the quotient becomes non-zero. For example, when all 3 trailing 0s are stripped from 4000 / 6...
... the quotient is 0 and the remainder is 4000. The operation pretty much failed because the amount of remaining items is the same as the amount starting amount -- nothing was grouped and everything remains. As such, more trialing 0s need to be left in. Re-try the operation with only 2 trialing 0s removed...
... the quotient is 600 and the remainder is 400. When 4000 items are broken up into groups of 6, there will be at least 600 groups. 400 of the 4000 items remain unaccounted for, but the rule can be used again on these 400 items because 400 has trailing 0s (recursive).
The idea behind long division is to break up the dividend into its individual single digit components results (idea 1) and divide each component by the divisor. For example, 752 / 3...
Each of the divisions are easy to perform because trialing 0s can be stripped-off prior to trial-and-error division (ideas 2 and 3). That is, the actual numbers being input into trial-and-error division are much smaller than they would normally be because trailing 0s are removed. Smaller numbers mean easier to perform.
⚠️NOTE️️️⚠️
The TE block is applying idea 3. The trialing 0s are being stripped off, trial-and-error division is being performed, then the 0s are re-append to the quotient and the remainder.
The remainders need to be accounted for. That is, if there are enough remaining items to form a group, they should be grouped. The process is repeated on the remaining items until there aren't enough to form a group (until the remainder is less than the divisor). Once there aren't enough remaining items to form a group, the sum of the quotients becomes the final quotient (final number of groups) and the remainder becomes the final remainder...
⚠️NOTE️️️⚠️
The diagram below looks daunting but it's just 3 copies of the diagrams above stacked on top of each other -- 1 for each iteration. The remainders from each iteration are being combined and used as the input for the next iteration. The quotients from each iteration are being combined to get the total quotient (total number of groups).
The diagram is intended to be an intermediary step to reasoning about long division. There's further simplification / explanation after it.
The answer to 752 / 3 is 250R2.
⚠️NOTE️️️⚠️
You can confirm this by doing 250 * 3 then adding 2. The result should be 752.
This process can be made much simpler by focusing on one component at a time. Starting from the largest component to the smallest component, divide (using idea 3) but then roll-in (add) the remainder into the next component. The thought process is exactly the same as above -- the division is being performed on a component and the remaining items from that division are being accounted for because they're being added to the next component (which gets divided next). For example, 752 / 3...
⚠️NOTE️️️⚠️
Notice how the inputs to TE still have trailing 0s.
Divide the largest component (700)...
Roll in remainder to the second largest component (50) and divide...
Roll in remainder to the third largest component (2) and divide...
The sum of the quotients becomes the final quotient, and the last remainder becomes the final remainder...
This is effectively the algorithm that humans use for long division -- for each component, divide (using idea 3) and roll in the remainder to the next component. Repeat the process until there are no components remaining.
The notation used by humans for long division is...
For example, long division notation for 752 / 3 is initially written as...
Starting with the first component, divide (using idea 3) to get the quotient and remainder for that component: 200R100. Then, strip-off the trialing 0s and place the quotient on-top of the component and the remainder below the component...
A question mark is sandwiched between the component and remainder. The question mark should be set to the value of the divisor (3) multiplied by the quotient (200), with its trailing 0s stripped out. 3 * 200 = 600, strip the trialing 0s to get 6...
⚠️NOTE️️️⚠️
The traditional way this is stated when being taught in school is "how many times can 7 go into 3?". Essentially, find the minimum number that the quotient can be without exceeding the component.
Put the answer to 3*2 = 6 underneath the component, then subtract to get the remainder...
Copy the next largest component down such that it's next the remainder...
This is effectively the same as adding the remainder to the next component: 100 + 50 = 150. Trailing 0s aren't seen because they're implied in long division notation.
⚠️NOTE️️️⚠️
The traditional way this is stated when being taught in school is "drag down the next component".
Repeat the process but target the 15 at the bottom. The 15 is the next component rolled into the remainder...
Copy the next largest component down such that it's next the remainder...
Repeat the entire process but target the 2 at the bottom. The 2 is the next component rolled into the remainder...
The final reminder isn't 0, so place it next to the final quotient...
The way to perform this algorithm via code is as follows...
@log_decorator
def __truediv__(dividend: WholeNumber, divisor: WholeNumber) -> (WholeNumber, WholeNumber):
if divisor == WholeNumber.from_int(0):
raise Exception('Cannot divide by 0')
log(f'Dividing {dividend} by {divisor}...')
log_indent()
count = len(dividend.digits)
quot = WholeNumber.from_int(0)
rem = WholeNumber.from_int(0)
for pos in reversed(range(0, count)): # from largest to smallest component
log(f'Targeting dividend: {dividend._highlight(pos)}, Current quotient: {quot} / Current remainder: {rem}')
log_indent()
comp = dividend[pos]
if pos == count - 1: # if this is the start component (largest component)...
comp_dividend = WholeNumber.from_digit(comp)
log(f'Set dividend: component ({comp}): {comp_dividend}')
else:
temp_rem = rem.copy()
temp_rem.shift_left(1)
comp_dividend = WholeNumber.from_digit(comp) + temp_rem
log(f'Set dividend: Combining prev remainder ({rem}) with component ({comp}): {comp_dividend}')
comp_quot, comp_rem = WholeNumber.trial_and_error_div(comp_dividend, divisor)
log(f'Trial-and-error division: {comp_dividend} / {divisor} = {comp_quot}R{comp_rem}')
new_quot = quot.copy()
new_quot.shift_left(1)
new_quot[0] = comp_quot[0] # comp_quot will always be a single digit
log(f'New quotient: Combining existing quotient ({quot}) with ({comp_quot}): {new_quot}')
log(f'New remainder: {comp_rem}')
quot = new_quot
rem = comp_rem
log_unindent()
log_unindent()
log(f'Final Quotient: {quot}, Final Remainder: {rem}')
return quot, remWhole number word conversion is the process of taking a whole number and converting it to words. To convert a whole number to words, break up the number into groups of 3 from least-significant digit to most-significant digit (right-to-left). For example, the number 9876543210 gets broken up as follows...
For each group, use the following algorithm to construct the words to represent that group:
If top digit exists, use the following mapping:
| Digit | Word |
|---|---|
| 0 | |
| 1 | one hundred |
| 2 | two hundred |
| 3 | three hundred |
| 4 | four hundred |
| 5 | five hundred |
| 6 | six hundred |
| 7 | seven hundred |
| 8 | eight hundred |
| 9 | nine hundred |
If middle digit is 1, combine in with the bottom digit and use the following mapping:
| Digits | Word |
|---|---|
| 10 | ten |
| 11 | eleven |
| 12 | twelve |
| 13 | thirteen |
| 14 | fourteen |
| 15 | fifteen |
| 16 | sixteen |
| 17 | seventeen |
| 18 | eighteen |
| 19 | nineteen |
If the middle digit isn't 1, use the following mapping:
| Digit | Word |
|---|---|
| 0 | |
| 2 | twenty |
| 3 | thirty |
| 4 | forty |
| 5 | fifty |
| 6 | sixty |
| 7 | seventy |
| 8 | eighty |
| 9 | ninety |
If the middle digit wasn't 1, use the following mapping for the bottom digit:
| Digit | Word |
|---|---|
| 0 | |
| 1 | one |
| 2 | two |
| 3 | three |
| 4 | four |
| 5 | five |
| 6 | six |
| 7 | seven |
| 8 | eight |
| 9 | nine |
In the example above, each group would get converted as follows...
The words for each group get a special suffix. For each group from right-to-left, ...
| Group | Word |
|---|---|
| 1 | |
| 2 | thousand |
| 3 | million |
| 4 | billion |
| 5 | trillion |
| ... | ... |
In the example above, each group would get its corresponding suffix added...
There is one special case with number to word conversions: if the number being converted is 0, the output should be zero.
The way to perform this algorithm via code is as follows...
@log_decorator
def to_words(self: WholeNumber) -> str:
suffixes = [None, 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion']
log(f'Converting {self}...')
log_indent()
output = ''
digits_copy = self.digits[:]
while not digits_copy == []:
d1 = digits_copy.pop(0) if digits_copy != [] else None
d2 = digits_copy.pop(0) if digits_copy != [] else None
d3 = digits_copy.pop(0) if digits_copy != [] else None
log(f'Converting group {d3} {d2} {d1}...')
log_indent()
txt = ''
if d3 is not None and d3 != Digit(0):
if d3.value == Digit(1):
txt += 'one hundred'
elif d3.value == Digit(2):
txt += 'two hundred'
elif d3.value == Digit(3):
txt += 'three hundred'
elif d3.value == Digit(4):
txt += 'four hundred'
elif d3.value == Digit(5):
txt += 'five hundred'
elif d3.value == Digit(6):
txt += 'six hundred'
elif d3.value == Digit(7):
txt += 'seven hundred'
elif d3.value == Digit(8):
txt += 'eight hundred'
elif d3.value == Digit(9):
txt += 'nine hundred'
else:
raise Exception()
ignore_first_digit = False
if d2 is not None and d3 != Digit(0):
txt += ' '
if d2.value == Digit(1):
ignore_first_digit = True
if d1 == Digit(0):
txt += 'ten'
elif d1 == Digit(1):
txt += 'eleven'
elif d1 == Digit(2):
txt += 'twelve'
elif d1 == Digit(3):
txt += 'thirteen'
elif d1 == Digit(4):
txt += 'fourteen'
elif d1 == Digit(5):
txt += 'fifteen'
elif d1 == Digit(6):
txt += 'sixteen'
elif d1 == Digit(7):
txt += 'seventeen'
elif d1 == Digit(8):
txt += 'eighteen'
elif d1 == Digit(9):
txt += 'nineteen'
else:
raise Exception()
elif d2.value == Digit(2):
txt += 'twenty'
elif d2.value == Digit(3):
txt += 'thirty'
elif d2.value == Digit(4):
txt += 'forty'
elif d2.value == Digit(5):
txt += 'fifty'
elif d2.value == Digit(6):
txt += 'sixty'
elif d2.value == Digit(7):
txt += 'seventy'
elif d2.value == Digit(8):
txt += 'eighty'
elif d2.value == Digit(9):
txt += 'ninety'
else:
raise Exception()
if not ignore_first_digit and d1 is not None and d1 != Digit(0):
txt += ' '
if d1.value == Digit(1):
txt += 'one'
elif d1.value == Digit(2):
txt += 'two'
elif d1.value == Digit(3):
txt += 'three'
elif d1.value == Digit(4):
txt += 'four'
elif d1.value == Digit(5):
txt += 'five'
elif d1.value == Digit(6):
txt += 'six'
elif d1.value == Digit(7):
txt += 'seven'
elif d1.value == Digit(8):
txt += 'eight'
elif d1.value == Digit(9):
txt += 'nine'
else:
raise Exception()
if suffixes == []:
raise Exception('Number too large')
log(f'Words: {txt}')
suffix = suffixes.pop(0)
if suffix is not None:
txt += ' ' + suffix
log(f'Suffix: {suffix}')
log_unindent()
output = txt + ' ' + output
output = output.lstrip()
if output == '':
output = 'zero'
log_unindent()
log(f'{output}')
return output.strip()↩PREREQUISITES↩
Integer numbers are place-value notation numbers that have no fractional part but are mirrored across 0. That is, think of integers as 2 sets of counting numbers separated by 0, where everything to the...
The prefix that determines if a integer is positive or negative is referred to as the sign. All numbers other than 0 have a sign. 0 represents nothing / no value, which is why it doesn't have a sign -- it's used as a separation point between the positive and negative values.
⚠️NOTE️️️⚠️
If a number (other than 0) is positive, the + sign is typically left out. So, ...
Conceptually, you can think of the positives the same way you think about natural numbers. They represent some value. For each positive, there's a corresponding negative that represents the opposite of that positive value. For example, if...
positive integers represent steps forward, then negative integers would represent steps backward.
positive integers represent money gained, then negative integers would represent money owed or spent.
positive integers represent depth below sea-level, then negative integers would represent elevation above sea-level.
↩PREREQUISITES↩
Integer equality is an extension of whole number equality. In whole number equality, the digit at each position must match between the numbers being compared. Integer equality adds an extra stipulation: the sign of the number must match as well.
For example, the numbers -195 and 195 are not equal...
- 1 9 5
x | | |
+ 1 9 5
... while the numbers -195 and -195 are equal...
- 1 9 5
| | | |
- 1 9 5
The way to perform this algorithm via code is as follows...
@log_decorator
def __eq__(self: IntegerNumber, other: IntegerNumber) -> bool:
log(f'Equality testing {self} and {other}...')
log_indent()
log(f'Testing sign equality ({self.sign} vs {other.sign})...')
sign_eq = self.sign == other.sign
log(f'{sign_eq}')
log(f'Testing magnitude equality ({self.magnitude} vs {other.magnitude})...')
mag_eq = self.magnitude == other.magnitude
log(f'{mag_eq}')
log_unindent()
ret = sign_eq and mag_eq
log(f'{ret}')
return ret↩PREREQUISITES↩
Recall that the number line for integers is more complex than the number line for whole numbers. The negatives and positives mirror at 0 and they grow in opposite directions:
The algorithm for integer less than applies different logic depending on the sign of each number. Specifically, if the numbers are...
both non-negative, apply the whole number less than algorithm. For example, 2 < 5 would be processed just as if it were a whole number...
⚠️NOTE️️️⚠️
Non-negative includes both 0 and positive numbers.
both non-positive, switch the negative sign to positive sign and apply the whole number greater than algorithm. For example, -5 < -2 would become 5 > 2...
After switching sign, the number being tested (5) is to the right of the other number (2). 5 > 2 would be processed just as if it were a whole number.
⚠️NOTE️️️⚠️
Non-positive includes both 0 and negative numbers.
negative and positive, return true only if the negative number is the one being tested. For example, 2 < -4 is false because 2 (the number being tested) isn't negative...
The way to perform this algorithm via code is as follows...
@log_decorator
def __lt__(self: IntegerNumber, other: IntegerNumber) -> bool:
log(f'Less than testing {self} and {other}...')
log_indent()
self_sign = self.sign
if self_sign is None: # assume 0 is a positive -- it simplifies logic below
self_sign = Sign.POSITIVE
other_sign = other.sign
if other_sign is None: # assume 0 is a positive -- it simplifies logic below
other_sign = Sign.POSITIVE
if self_sign == Sign.POSITIVE and other_sign == Sign.POSITIVE:
log(f'{self.sign} < {other.sign}: Applying whole number less than...')
ret = self.magnitude < other.magnitude
elif self_sign == Sign.NEGATIVE and other_sign == Sign.NEGATIVE:
log(f'{self.sign} < {other.sign}: Turning positive and applying whole number greater than...')
ret = self.magnitude > other.magnitude
elif self_sign == Sign.POSITIVE and other_sign == Sign.NEGATIVE:
log(f'{self.sign} < {other.sign}:: Different signs -- number being tested is positive...')
ret = False
elif self_sign == Sign.NEGATIVE and other_sign == Sign.POSITIVE:
log(f'{self.sign} < {other.sign}: Different signs -- number being tested is negative...')
ret = True
log(f'{ret}')
log_unindent()
log(f'{ret}')
return ret↩PREREQUISITES↩
Recall that the number line for integers is more complex than the number line for whole numbers. The negatives and positives mirror at 0 and they grow in opposite directions:
The algorithm for integer greater than applies different logic depending on the sign of each number. Specifically, if the numbers are...
both non-negative, apply the whole number greater than algorithm. For example, 5 > 2 would be processed just as if it were a whole number...
⚠️NOTE️️️⚠️
Non-negative includes both 0 and positive numbers.
both non-positive, switch the negative sign to positive sign and apply the whole number less than algorithm. For example, -2 > -5 would become 2 < 5...
After switching sign, the number being tested (2) is to the left of the other number (5). 2 < 5 would be processed just as if it were a whole number.
⚠️NOTE️️️⚠️
Non-positive includes both 0 and negative numbers.
negative and positive, return true only if the positive number is the one being tested. For example, 2 > -4 is true because 2 (the number being tested) is positive...
The way to perform this algorithm via code is as follows...
@log_decorator
def __gt__(self: IntegerNumber, other: IntegerNumber) -> bool:
log(f'Greater than testing {self} and {other}...')
log_indent()
self_sign = self.sign
if self_sign is None: # assume 0 is a positive -- it simplifies logic below
self_sign = Sign.POSITIVE
other_sign = other.sign
if other_sign is None: # assume 0 is a positive -- it simplifies logic below
other_sign = Sign.POSITIVE
if self_sign == Sign.POSITIVE and other_sign == Sign.POSITIVE:
log(f'{self.sign} > {other.sign}: Applying whole number less than...')
ret = self.magnitude > other.magnitude
elif self_sign == Sign.NEGATIVE and other_sign == Sign.NEGATIVE:
log(f'{self.sign} > {other.sign}: Turning positive and applying whole number greater than...')
ret = self.magnitude < other.magnitude
elif self_sign == Sign.POSITIVE and other_sign == Sign.NEGATIVE:
log(f'{self.sign} > {other.sign}:: Different signs -- number being tested is positive...')
ret = True
elif self_sign == Sign.NEGATIVE and other_sign == Sign.POSITIVE:
log(f'{self.sign} > {other.sign}: Different signs -- number being tested is negative...')
ret = False
log(f'{ret}')
log_unindent()
log(f'{ret}')
return ret↩PREREQUISITES↩
Conceptually, you can think of integer addition as movement on a number line. If some integer is being added to a...
positive integer, it's moving right on the number line.
For example, 3 + 4 is 7...
For example, -5 + 4 is -1...
Notice that the result of this example's movement is exactly the same as subtracting magnitudes, then tacking on a negative sign to the result: 5 - 4 is 1, tack on a negative sign to get -1.
negative integer, it's moving left on the number line.
For example, -1 + -4 is -5...
Notice that the result of this example's movement is exactly the same as adding magnitudes, then tacking on a negative sign to the result: 1 + 4 is 5, tack on a negative sign to get -5.
For example, 3 + -4 is -1...
Notice that the result of this example's movement is exactly the same as swapping, subtracting, then tacking on a negative sign to the result: 4 - 3 is 1, tack on a negative sign: -1.
The algorithm used by humans to add integer numbers together revolves around inspecting the sign and magnitude of each integer, then deciding whether to perform whole number addition or whole number subtraction to get the result. The codification of this algorithm is as follows...
@log_decorator
def __add__(lhs: IntegerNumber, rhs: IntegerNumber) -> IntegerNumber:
log(f'Adding {lhs} and {rhs}')
log_indent()
def determine_sign(magnitude: WholeNumber, default_sign: Sign) -> Sign:
if magnitude == WholeNumber.from_int(0):
return None
else:
return default_sign
if lhs.sign is None: # sign of None is only when magnitude is 0, 0 + a = a
sign = rhs.sign
magnitude = rhs.magnitude
elif rhs.sign is None: # sign of None is only when magnitude is 0, a + 0 = a
sign = lhs.sign
magnitude = lhs.magnitude
elif lhs.sign == rhs.sign:
magnitude = lhs.magnitude + rhs.magnitude
sign = determine_sign(magnitude, lhs.sign)
elif lhs.sign != rhs.sign:
if rhs.magnitude >= lhs.magnitude:
magnitude = rhs.magnitude - lhs.magnitude
sign = determine_sign(magnitude, rhs.sign)
else:
magnitude = lhs.magnitude - rhs.magnitude
sign = determine_sign(magnitude, lhs.sign)
log_unindent()
log(f'sign: {sign}, magnitude: {magnitude}')
return IntegerNumber(sign, magnitude)Conceptually, you can think of integer subtraction as movement on a number line (opposite movement to that of integer addition). If the integer being subtracted by (right-hand side) is a...
positive integer, it's moving left on the number line.
For example, 5 - 4 is 1...
For example, -2 - 4 is -6...
Notice that the result of this example's movement is exactly the same as adding magnitudes, then tacking on a negative sign to the result: 2 + 4 is 6, tack on a negative sign to get -6.
For example, 3 - 4 is -1...
Notice that the result of this example's movement is exactly the same as swapping, subtracting, then tacking on a negative sign: 4 - 3 is 1, tack on a negative sign to get -1.
negative integer, it's moving right on the number line.
For example, 3 - -4 is 7...
Notice that the result of this movement is exactly the same as performing 3 + 4.
For example, -3 - -4 is 1...
Notice that the result of this example's movement is exactly the same as swapping, subtracting, then tacking on a positive sign to the result: 4 - 3 is 1, tack on a positive sign: 1.
The algorithm used by humans to subtract integer numbers revolves around inspecting the sign and magnitude of each integer, then deciding whether to perform whole number addition or whole number subtraction to get the result. The codification of this algorithm is as follows...
@log_decorator
def __sub__(lhs: IntegerNumber, rhs: IntegerNumber) -> IntegerNumber:
log(f'Subtracting {lhs} and {rhs}')
log_indent()
def determine_sign(magnitude: WholeNumber, default_sign: Sign) -> Sign:
if magnitude == WholeNumber.from_int(0):
return None
else:
return default_sign
def flip_sign(sign: Sign) -> Sign:
if sign == Sign.POSITIVE:
return Sign.NEGATIVE
elif sign == Sign.NEGATIVE:
return Sign.POSITIVE
if lhs.sign is None: # sign of None is only when magnitude is 0, 0 - a = -a
sign = flip_sign(rhs.sign)
magnitude = rhs.magnitude
elif rhs.sign is None: # sign of None is only when magnitude is 0, a - 0 = a
sign = lhs.sign
magnitude = lhs.magnitude
elif lhs.sign == rhs.sign:
if rhs.magnitude >= lhs.magnitude:
magnitude = rhs.magnitude - lhs.magnitude
sign = determine_sign(magnitude, flip_sign(lhs.sign))
else:
magnitude = lhs.magnitude - rhs.magnitude
sign = determine_sign(magnitude, lhs.sign)
elif lhs.sign != rhs.sign:
magnitude = lhs.magnitude + rhs.magnitude
sign = determine_sign(magnitude, lhs.sign)
log_unindent()
log(f'sign: {sign}, magnitude: {magnitude}')
return IntegerNumber(sign, magnitude)Conceptually, you can think of integer multiplication as repetitive integer addition / integer subtraction. When the right hand side is negative, think of it as subtraction instead of addition. For example, think of ...
5 * 3 as add 5, 3 times
-5 * 3 as add -5, 3 times
3 * -5 as subtract 5, 3 times
⚠️NOTE️️️⚠️
Subtraction starts from 0, so it'd be...
Or, you could use the commutative property of multiplication and swap the operands -- 3 * -5 becomes -5 * 3, exactly the same as the previous bullet point.
-5 * -3 as subtract -5, 3 times
One useful property of integer multiplication is that, multiplying any non-zero number by -1 will slip its sign. For example...
5 * -1 is -5
-5 * -1 is 5
The algorithms humans use to perform integer multiplication is as follows:
The result produced using the algorithm will be exactly the same as the result produced using repetitive addition/subtraction.
The way to perform this algorithm via code is as follows...
@log_decorator
def __mul__(lhs: IntegerNumber, rhs: IntegerNumber) -> IntegerNumber:
log(f'Multiplying {lhs} and {rhs}')
log_indent()
def determine_sign(magnitude: WholeNumber, default_sign: Sign) -> Sign:
if magnitude == WholeNumber.from_int(0):
return None
else:
return default_sign
if lhs.sign is None: # when sign isn't set, magnitude is always 0 -- 0 * a = 0
sign = None
magnitude = WholeNumber.from_int(0)
elif rhs.sign is None: # when sign isn't set, magnitude is always 0 -- a * 0 = 0
sign = None
magnitude = WholeNumber.from_int(0)
elif (lhs.sign == Sign.POSITIVE and rhs.sign == Sign.POSITIVE) \
or (lhs.sign == Sign.NEGATIVE and rhs.sign == Sign.NEGATIVE):
magnitude = lhs.magnitude * rhs.magnitude
sign = determine_sign(magnitude, Sign.POSITIVE)
elif (lhs.sign == Sign.POSITIVE and rhs.sign == Sign.NEGATIVE) \
or (lhs.sign == Sign.NEGATIVE and rhs.sign == Sign.POSITIVE):
magnitude = lhs.magnitude * rhs.magnitude
sign = determine_sign(magnitude, Sign.NEGATIVE)
log_unindent()
log(f'sign: {sign}, magnitude: {magnitude}')
return IntegerNumber(sign, magnitude)↩PREREQUISITES↩
Conceptually, you can think of integer division the same as whole number division: repetitive integer subtraction -- how many iterations can be subtracted until reaching 0. When both numbers being divided have the same sign, the process is nearly the same as whole number division. For example, ...
15 / 3 -- how many iterations og subtracting by 3 before 15 reaches 0
You need to subtract by 3 to get closer to 0...
5 iterations of subtraction.
-15 / -3 -- how many iterations of subtracting by -3 before -15 reaches 0
You need to subtract by -3 to get closer to 0...
5 iterations of subtraction.
When the sign are different, it becomes slightly more difficult to conceptualize. For example, using repetitive subtraction on -15 / 3 will get farther from 0 rather than closer:
In cases such as this, the concept of negative iterations is needed. For example, when ...
Why? The inverse (opposite) of subtraction is addition. Performing -5 iterations means doing the opposite for 5 iterations.
⚠️NOTE️️️⚠️
Remember that for integer numbers, a negative integer is one that's the mirror opposite of the positive (and vice versa).
-15 / 3 -- how many iterations of subtracting by 3 before -15 reaches 0
You need to add by 3 to get closer to 0...
-5 iterations of subtraction.
15 / -3 -- how many iterations of subtracting by -3 before 15 reaches 0
You need to add by -3 to get closer to 0...
-5 iterations of subtraction.
The algorithms humans use to perform integer multiplication is as follows:
The result produced using the algorithm will be exactly the same as the result produced using repetitive subtraction.
The way to perform this algorithm via code is as follows...
@log_decorator
def __truediv__(lhs: IntegerNumber, rhs: IntegerNumber) -> (IntegerNumber, IntegerNumber):
log(f'Dividing {lhs} and {rhs}')
log_indent()
def determine_sign(magnitude: WholeNumber, default_sign: Sign) -> Sign:
if magnitude == WholeNumber.from_int(0):
return None
else:
return default_sign
if lhs.sign is None: # when sign isn't set, magnitude is always 0 -- 0 / a = 0
(quotient_magnitude, remainder_magnitude) = lhs.magnitude / rhs.magnitude
quotient_sign = None
remainder_sign = None
elif rhs.sign is None: # when sign isn't set, magnitude is always 0 -- a / 0 = err
raise Exception('Cannot divide by 0')
elif (lhs.sign == Sign.POSITIVE and rhs.sign == Sign.POSITIVE) \
or (lhs.sign == Sign.NEGATIVE and rhs.sign == Sign.NEGATIVE):
(quotient_magnitude, remainder_magnitude) = lhs.magnitude / rhs.magnitude
quotient_sign = determine_sign(quotient_magnitude, Sign.POSITIVE)
remainder_sign = determine_sign(remainder_magnitude, Sign.POSITIVE)
elif (lhs.sign == Sign.POSITIVE and rhs.sign == Sign.NEGATIVE) \
or (lhs.sign == Sign.NEGATIVE and rhs.sign == Sign.POSITIVE):
(quotient_magnitude, remainder_magnitude) = lhs.magnitude / rhs.magnitude
quotient_sign = determine_sign(quotient_magnitude, Sign.NEGATIVE)
remainder_sign = determine_sign(remainder_magnitude, Sign.NEGATIVE)
log_unindent()
log(f'QUOTIENT: sign: {quotient_sign}, magnitude: {quotient_magnitude}')
log(f'REMAINDER: sign: {remainder_sign}, magnitude: {remainder_magnitude}')
return IntegerNumber(quotient_sign, quotient_magnitude), IntegerNumber(remainder_sign, remainder_magnitude)↩PREREQUISITES↩
Integer word conversion is the process of taking an integer number and converting it to words. The algorithm used by humans to convert an integer number to words is as follows:
Begin by converting the sign to a word. If the number is ...
⚠️NOTE️️️⚠️
Then, write out the actual number as you would during whole number word conversion.
For example, the number...
The way to perform this algorithm via code is as follows...
@log_decorator
def to_words(self: IntegerNumber) -> str:
log(f'Converting {self}...')
output = ''
if self.sign == Sign.NEGATIVE:
output += 'negative '
output += self.magnitude.to_words()
log_unindent()
log(f'{output}')
return output.lstrip()↩PREREQUISITES↩
To say that m is a multiple of n means that some integer exists such that when you multiply it by n you get m:- . Typically both n and m are also integers.
For example, the multiples of 2 are...
2*0=2 -- 0 is a multiple of 2
2*1=2 -- 2 is a multiple of 2
┌──┐
│●●│ 2 can be grouped as 1 group of 2
└──┘
2*2=4 -- 4 is a multiple of 2
┌──┬──┐
│●●│●●│ 4 can be grouped as 2 groups of 2
└──┴──┘
2*3=6 -- 6 is a multiple of 2
┌──┬──┬──┐
│●●│●●│●●│ 6 can be grouped as 3 groups of 2
└──┴──┴──┘
2*4=8 -- 8 is a multiple of 2
┌──┬──┬──┬──┐
│●●│●●│●●│●●│ 8 can be grouped as 4 groups of 2
└──┴──┴──┴──┘
etc..
A number like 7 wouldn't be a multiple of 2 because there is no integer that can be multiplied by 2 to get 7 -- 2*3.5=7, but 3.5 isn't an integer.
┌──┬──┬──┬─┐
│●●│●●│●●│●│ 7 can't be grouped as groups of 2 (last group only has 1)
└──┴──┴──┴─┘
⚠️NOTE️️️⚠️
See divisible section.
↩PREREQUISITES↩
To say that m is divisible by n means that an integer results from dividing m by n: . Typically both m and n are also integers, with the exception that n can't be 0 (can't divide by 0).
For example, 8 is divisible by...
8/1=8 -- 8 is divisible by 1
┌────────┐
│●●●●●●●●│ 8 can be grouped as 1 group of 8
└────────┘
8/2=4 -- 8 is divisible by 2
┌────┬────┐
│●●●●│●●●●│ 8 can be grouped as 2 groups of 4
└────┴────┘
8/4=2 -- 8 is divisible by 4
┌──┬──┬──┬──┐
│●●│●●│●●│●●│ 8 can be grouped as 4 groups of 2
└──┴──┴──┴──┘
8/8=1 -- 8 is divisible by 8
┌─┬─┬─┬─┬─┬─┬─┬─┐
│●│●│●│●│●│●│●│●│ 8 can be grouped as 8 groups of 1
└─┴─┴─┴─┴─┴─┴─┴─┘
In all of the above cases, the quotient is an integer -- it doesn't have a remainder. 8 wouldn't be divisible by a number like 3 because the result wouldn't be an integer. 8/3=2.6667, but 2.6667 isn't an integer.
┌───┬───┬──┐
│●●●│●●●│●●│ 8 can't be grouped as groups of 3 (last group only has 2)
└───┴───┴──┘
⚠️NOTE️️️⚠️
The phrases evenly divisible, evenly divides and divisible all mean the same thing.
The phrase evenly divides into is the same as divides into but that it doesn't have a remainder (whole). 4 divides into 8 (4/8=2), but 6 doesn't divide into 8 (6/8=0.75).
⚠️NOTE️️️⚠️
Divisible and multiple refer to the same idea. Saying that 275 is a multiple of 5 () is the same as saying 275 is divisible by 5 ().
Common divisibility tests are simple tests you can do on a number to see if its divisible. To see if a number is divisible by...
2, check if the last digit is either 0, 2, 4, 6, or 8.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
| 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
5, check if the last digit is either 5 or 0.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
| 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
10, check if the last digit is 0.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
| 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
3, sum up the individual digits and check if divisibly by 3.
This is a recursive operation. For example...
Keep doing it until you get a 1 digit answer and check to see if that answer is either 3, 6, or 9.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
| 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
| 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
6, apply common divisibility tests for 2 and 3, they both must pass.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
| 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
| 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
⚠️NOTE️️️⚠️
The bold numbers in the table above are numbers that appear bold in both the table for 2s and the table for 3s -- they must be bold in both tables.
The common divisibility test algorithm written as code is as follows:
def common_divisibility_test(num: WholeNumber) -> Set[WholeNumber]:
log_indent()
try:
ret: Set[WholeNumber] = set()
last_digit: WholeNumber = WholeNumber.from_digit(num.digits[0]) # last digit is always at 0 idx
log(f'Testing if {num} divisible by 2...')
if last_digit == WholeNumber.from_int(0) \
or last_digit == WholeNumber.from_int(2) \
or last_digit == WholeNumber.from_int(4) \
or last_digit == WholeNumber.from_int(6) \
or last_digit == WholeNumber.from_int(8):
log(f'Yes')
ret.add(WholeNumber.from_int(2))
else:
log(f'No')
log(f'Testing if {num} divisible by 5...')
if last_digit == WholeNumber.from_int(0) \
or last_digit == WholeNumber.from_int(5):
log(f'Yes');
ret.add(WholeNumber.from_int(5))
else:
log(f'No');
log(f'Testing if {num} divisible by 10...')
if last_digit == WholeNumber.from_int(0):
log(f'Yes');
ret.add(WholeNumber.from_int(10))
else:
log(f'No');
log(f'Testing if {num} divisible by 3...')
reduced_num: WholeNumber = num.copy()
while True:
digits = reduced_num.digits
if len(digits) == 1:
break
reduced_num = sum([WholeNumber.from_int(d) for d in digits], WholeNumber.from_int(0))
if reduced_num == WholeNumber.from_int(3) \
or reduced_num == WholeNumber.from_int(6) \
or reduced_num == WholeNumber.from_int(9):
log(f'Yes')
ret.add(WholeNumber.from_int(3))
else:
log(f'No')
log(f'Testing if {num} divisible by 6...')
if WholeNumber.from_int(2) in ret and WholeNumber.from_int(3) in ret:
log(f'Yes')
ret.add(WholeNumber.from_int(6))
else:
log(f'NO')
return ret
finally:
log_unindent()For example, the common divisibility tests for 18...
↩PREREQUISITES↩
Let's say you have an integer number. The factors of that number are the integers you can multiply together to get that number...
my_number: int = ...;
factor1: int = ...;
factor2: int = ...;
if (factor1 * factor2 == my_number):
print(f'{factor1} and {factor2} are factors of {my_number});
For example, the factors of 32 are...
... 1, 2, 4, 8, 16, and 32.
⚠️NOTE️️️⚠️
Shouldn't negative integers also be a factor? e.g. 32=-1*-32. It turns out that for positive integers, negative factors aren't included? For negative integers, they are. Factoring negative integers is discussed further below in this section.
See https://math.stackexchange.com/a/404789
The factors for any number will always be between 1 and that number (inclusive). A naive algorithm for finding the factors of any number would be to have a nested loop exhaustively check integers to see which are factors...
@log_decorator
def factor_naive(num: WholeNumber) -> Set[WholeNumber]:
log(f'Factoring {num}...')
log_indent()
factors: Set[WholeNumber] = set()
for factor1 in WholeNumber.range(WholeNumber.from_int(1), num, end_inclusive=True):
for factor2 in WholeNumber.range(WholeNumber.from_int(1), num, end_inclusive=True):
log(f'Testing if {factor1} and {factor2} are factors...')
if factor1 * factor2 == num:
factors.add(factor1)
factors.add(factor2)
log(f'Yes')
else:
log(f'No')
log_unindent()
log(f'{factors}')
return factorsWe can take advantage of the fact that division is the inverse of multiplication to optimize the algorithm above. The code below loops over each possible factor once, using it to calculate what the other factor would be and then checking it to make sure it's valid...
@log_decorator
def factor_fast(num: WholeNumber) -> Set[WholeNumber]:
log(f'Factoring {num}...')
log_indent()
factors: Set[WholeNumber] = set()
for factor1 in WholeNumber.range(WholeNumber.from_int(1), num, end_inclusive=True):
log(f'Test if {factor1} is a factor...')
factor2, remainder = num / factor1
if remainder == WholeNumber.from_int(0):
factors.add(factor1)
factors.add(factor2)
log(f'Yes: ({factor1} and {factor2} are factors)')
else:
log(f'No')
log_unindent()
log(f'{factors}')
return factors
#MARKDOWN_FAST
#MARKDOWN_FASTEST
@log_decorator
def factor_fastest(num: WholeNumber) -> Set[WholeNumber]:
log(f'Factoring {num}...')
log_indent()
factors: Set[WholeNumber] = set()
for factor1 in WholeNumber.range(WholeNumber.from_int(1), num, end_inclusive=True):
log(f'Test if {factor1} is a factor...')
factor2, remainder = num / factor1
if remainder == WholeNumber.from_int(0):
factors.add(factor1)
factors.add(factor2)
log(f'Yes: ({factor1} and {factor2} are factors)')
else:
log(f'No')
if factor2 <= factor1:
break
log_unindent()
log(f'{factors}')
return factorsThe optimized algorithm above can be even further optimized by making it skip over calculations that give back repeat factors. As factor1 increases, factor2 decreases. Once factor1 => factor2, each is basically walking into domains the other was just in (they're each going to walk over integers the other already walked over). There's no point in continuing any further because the factors calculated past that point will just be duplicates of those prior. For example, when calculating the factors of 32...
Any factors calculated past factor1 => factor2 will be duplicates of factors that were already walked over...
@log_decorator
def factor_fastest(num: WholeNumber) -> Set[WholeNumber]:
log(f'Factoring {num}...')
log_indent()
factors: Set[WholeNumber] = set()
for factor1 in WholeNumber.range(WholeNumber.from_int(1), num, end_inclusive=True):
log(f'Test if {factor1} is a factor...')
factor2, remainder = num / factor1
if remainder == WholeNumber.from_int(0):
factors.add(factor1)
factors.add(factor2)
log(f'Yes: ({factor1} and {factor2} are factors)')
else:
log(f'No')
if factor2 <= factor1:
break
log_unindent()
log(f'{factors}')
return factorsThere are 2 special cases when dealing with factors...
The first is that all numbers are a factor of 0 (e.g. 0*5=0, 0*9999=0).
The second is that if the number were a negative integer, the factors would include negative numbers as well. For example, the factors of -8 are...
... -8, -4, -2, -1, 1, 2, 4, 8.
A counting number with only 2 factors is called a prime number. That is, if a counting number is only divisible by 1 and it itself, it's a prime number. Examples of prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, and 47.
A counting number with more than 2 factors is called a composite number. Examples of composite numbers: 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, and 20.
⚠️NOTE️️️⚠️
The number 1 is neither a prime number nor a composite number. 1's only factor is itself: 1*1=1. Prime numbers need 2 factors (1 and itself) and composite numbers need more than 2 factors.
The algorithm to identify primes vs composites is as follows...
@log_decorator
def is_prime(num: WholeNumber) -> bool:
log(f'Test if {num} is prime...')
log_indent()
num_factors = factor_fastest(num)
# At a minimum, all counting numbers have the factors 1 and the number itself (2 factors). If
# there are more factore than that, it's a composite. Otherwise, it's a primse.
log_unindent()
if len(num_factors) == 2:
log(f'{num}\'s factors are {num_factors} -- it is a prime');
return True
else:
log(f'{num}\'s factors are {num_factors} -- it is a composite');
return FalseEvery composite number can be written as a product of prime numbers. For example...
The process of breaking down a composite number into a product of primes is called prime factorization. There are 2 algorithms that humans use to factorize primes: factor tree method and ladder method. Each method is described below.
The factor tree method is an algorithm used by humans for prime factorization. The algorithm involves taking the input and recursively breaking it down into one of its factor pairs until all factors are prime.
For example, to break down the number 54, choose one of its factor pairs...
Then, for each factor, break it down even further by choosing one of its factor pairs...
All factors are now prime -- 54 = 3*2*3*3.
⚠️NOTE️️️⚠️
Prime factors are typically written out from smallest to largest, so writing out the prime factors of the example above would be 54 = 2*3*3*3.
If you know exponents, the example above can be further condensed as .
When choosing a factor pair, the pair can't include 1 or the number being factored itself. For example, if choosing a factor pair for 12..
The reason why ...
For example, trying to build a factor tree for 12 using one of the bad factor pairs...
Note that the prime factors for a number will always be the same regardless of which factor pairs are chosen (as long as its a valid factor pair). For example, in the initial example above, if 54 were factored to (2, 27) instead of (9, 6) ...
The prime factors would still be 54 = 2*3*3*3.
The way to perform this algorithm as code is as follows...
@log_decorator
def factor_tree(num: WholeNumber) -> FactorTreeNode:
log(f'Creating factor tree for {num}...')
factors = factor_fastest(num)
# remove factor pairs that can't used in factor true: (1, num) or (num, 1)
factors = set([f for f in factors if f != WholeNumber.from_int(1) and f != num])
ret = FactorTreeNode()
if len(factors) == 0:
ret.value = num
log(f'Cannot factor {num} is prime -- resulting tree: {ret}')
else:
factor1 = next(iter(factors))
factor2, _ = num / factor1
ret.value = num
ret.left = factor_tree(factor1)
ret.right = factor_tree(factor2)
log(f'Factored {num} to {factor1} and {factor2} -- resulting tree: {ret}')
return retLadder
The ladder method is an algorithm used by humans for prime factorization. The algorithm involves:
⚠️NOTE️️️⚠️
The ladder method is sometimes referred to as stacked division.
For example, to break down the number 54, start by iteratively dividing 54 by primes until its divisible (no remainder)...
Dividing by 2 results in 27 -- no remainder. Iteratively divide 27 by primes until its divisible (no remainder)...
Dividing by 3 results in 9 -- no remainder. Iteratively divide 9 by primes until its divisible (no remainder).
Dividing by 3 results in 3 -- no remainder. The process stops because 3 (the quotient) is a prime.
All factors are now prime -- 54 = 2*3*3*3.
⚠️NOTE️️️⚠️
Prime factors are typically written out from smallest to largest, so writing out the prime factors of the example above would be 54 = 2*3*3*3.
If you know exponents, the example above can be further condensed as .
Note that factor tree method and the ladder method are effectively doing the same thing. The only difference is that the ladder method is forcing you to choose a factor pair with a prime in it -- it's testing primes to see if they're viable factor pairs.
The ladder above is represented as the following factor tree...
The way to perform this algorithm as code is as follows...
@log_decorator
def ladder(num: WholeNumber) -> Set[WholeNumber]:
prime_factors: List[WholeNumber] = []
log(f'Testing primes (using ladder method) to see which is factor of {num}...')
log_indent()
while not is_prime(num):
prime_to_test = WholeNumber.from_int(2)
while True:
log(f'Testing if {prime_to_test} is divisible by {num}...')
(new_num, remainder) = num / prime_to_test
if remainder == WholeNumber.from_int(0):
break
prime_to_test = calculate_next_prime(prime_to_test)
log(f'Found! {prime_to_test} is a prime factor -- {new_num} * {prime_to_test} = {num}')
prime_factors.append(prime_to_test)
num = new_num
log(f'Testing primes to see which is factor of {num}...')
log(f'{num} itself is a prime!')
prime_factors.append(num)
log_unindent()
log(f'Prime factors: {prime_factors}')
return prime_factors↩PREREQUISITES↩
The least common multiple is the process of taking 2 numbers and finding the smallest multiple between them. That is, if you listed out their multiples starting from 1, the first match between them would be the least common multiple.
There are 2 common algorithms used to find the least common multiple between 2 numbers.
The first algorithm is called the listing multiples method. It involves listing out the multiples for each number starting from 1 until there's a match. For example, finding the least common multiple between 4 and 6...
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
|---|---|---|---|---|---|---|---|---|---|
| 4 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 |
| 6 | 6 | 12 | 18 | 24 | 30 | 36 |
is 12 because 6*2 is 12 and 4*3 is 12.
The way to perform this algorithm as code is as follows...
@log_decorator
def lcm_walk(num1: WholeNumber, num2: WholeNumber) -> Tuple[List[WholeNumber], List[WholeNumber]]:
num1_multiples: List[WholeNumber] = []
num2_multiples: List[WholeNumber] = []
num1_counter = WholeNumber.from_int(1)
num2_counter = WholeNumber.from_int(1)
while True:
log(f'Calculating {num1_counter} multiple of {num1}...')
num1_multiple = num1 * num1_counter
num1_multiples.append(num1_multiple)
log(f'Calculating {num2_counter} multiple of {num2}...')
num2_multiple = num2 * num2_counter
num2_multiples.append(num2_multiple)
log(f'Testing {num1_multiple} vs {num2_multiple}')
if num1_multiple == num2_multiple:
log(f'Matches! LCM is {num1_multiple}')
break
elif num1_multiple < num2_multiple:
log(f'Increasing first multiple (multiple for {num1})')
num1_counter += WholeNumber.from_int(1)
elif num1_multiple > num2_multiple:
log(f'Increasing second multiple (multiple for {num2})')
num2_counter += WholeNumber.from_int(1)
return num1_multipleThe second algorithm is called the prime factors method. It involves calculating the prime factors for each number and merging them to get the least common multiple. For example, finding the least common multiple between 4 and 6...
prime factors of 4: 4 = 2 * 2
prime factors of 6: 6 = 2 * 2 * 3
merge the prime factors together to get 12 = 2 * 2 * 3
The way to perform this algorithm as code is as follows...
@log_decorator
def lcm_prime_factorize(num1: WholeNumber, num2: WholeNumber) -> WholeNumber:
log(f'Calculating prime factors for {num1}...')
num1_primes = sorted(factor_tree(num1).get_prime_factors())
log(f'{num1_primes}')
log(f'Calculating prime factors for {num2}...')
num2_primes = sorted(factor_tree(num2).get_prime_factors())
log(f'{num2_primes}')
distinct_primes: Set[WholeNumber] = set()
[distinct_primes.add(p) for p in num1_primes]
[distinct_primes.add(p) for p in num2_primes]
log(f'Combining prime factors to get LCM...')
least_common_multiple = WholeNumber.from_int(1)
least_common_multiple_primes = Counter()
for prime in sorted(list(distinct_primes)):
num1_count = num1_primes.count(prime)
num2_count = num2_primes.count(prime)
if num1_count >= num2_count:
for i in WholeNumber.range(WholeNumber.from_int(0), WholeNumber.from_int(num1_count)):
least_common_multiple = least_common_multiple * prime
least_common_multiple_primes[prime] += num1_count
else:
for i in WholeNumber.range(WholeNumber.from_int(0), WholeNumber.from_int(num2_count)):
least_common_multiple = least_common_multiple * prime
least_common_multiple_primes[prime] += num2_count
log(f'LCM is {least_common_multiple}')
return least_common_multiple↩PREREQUISITES↩
The greatest common divisor is the process of taking 2 numbers and finding the largest possible divisor between the two of them. That is, finding the greatest number that evenly divides both numbers.
⚠️NOTE️️️⚠️
This is also referred to as the highest common factor -- you're finding the largest factor that's common in both of them. Common factors between the numbers will evenly divide both numbers.
There are 3 common algorithms used to find the greatest common divisor between 2 numbers.
The first algorithm is to test divisions on incrementally larger numbers until you reach the smaller of the 2 numbers. The largest tested number that was evenly divisible is the greatest common divisor. For example, for the numbers 22 and 8...
The greatest common divisor is 2.
The way to perform this algorithm as code is as follows...
@log_decorator
def gcd_naive(num1: WholeNumber, num2: WholeNumber) -> WholeNumber:
log(f'Calculating gcd for {num1} and {num2}...')
log_indent()
log(f'Sorting to determine smaller input...')
min_num = min(num1, num2)
log(f'Testing up to smaller input ({min_num})...')
log_indent()
for i in WholeNumber.range(WholeNumber.from_str('1'), min_num, True):
log(f'Testing {i}...')
quotient1, remainder1 = num1 / i
quotient2, remainder2 = num2 / i
if remainder1 == 0 and remainder2 == 0:
log(f'{num1} and {num2} are both divisible by {i}...')
found = i
else:
log(f'{num1} and {num2} are NOT both divisible by {i}...')
log_unindent()
log_unindent()
log(f'GCD is {found}')
return foundThe second algorithm is to factor both numbers and take the largest common factor between them. The largest common factor is the greatest common divisor. For example, for the numbers 22 and 8, ...
The greatest common factor between them is 2.
⚠️NOTE️️️⚠️
You can also use prime factorization. Prime factorize both numbers to their prime factors -- any factors contained in both are prime factors of the greatest common divisor. For example...
The way to perform this algorithm as code is as follows...
@log_decorator
def gcd_factor(num1: WholeNumber, num2: WholeNumber) -> WholeNumber:
log(f'Calculating gcd for {num1} and {num2}...')
log_indent()
log(f'Calculating factors for {num1}...')
factors1 = factor_fastest(num1)
log(f'Factors for {num1}: {factors1}')
log(f'Calculating factors for {num2}...')
factors2 = factor_fastest(num2)
log(f'Factors for {num2}: {factors2}')
log(f'Finding common factors...')
common_factors = factors1 & factors2 # set intersection
log(f'Common factors for {num1} and {num2}: {common_factors}')
found = max(common_factors)
log_unindent()
log(f'GCD is {found}')
return foundThe third algorithm is to use Euclid's algorithm to compute the greatest common divisor. This is the algorithm most used by both humans and computers to calculate the greatest common divisor because, for large numbers, it's less labour intensive than the other two methods.
Imagine the numbers 8 and 22. The algorithm starts by sorting the numbers from largest to smallest and dividing them:
It then takes the divisor and the remainder, sorts them from largest to smallest, and divides them again:
It keeps repeating this process until the remainder reaches 0. For this example, it only needs to repeat the process one more time:
The greatest common factor is the divisor when the remainder is 0. In this example, it's 2.
The way to perform this algorithm as code is as follows...
@log_decorator
def gcd_euclid(num1: WholeNumber, num2: WholeNumber) -> WholeNumber:
log(f'Calculating gcd for {num1} and {num2}...')
log_indent()
next_nums = [num1, num2]
while True:
log(f'Sorting {next_nums}...')
next_nums.sort() # sort smallest to largest
next_nums.reverse() # reverse it so that it's largest to largest
log(f'Checking if finished ({next_nums[1]} == 0?)...')
if next_nums[1] == WholeNumber.from_int(0):
found = next_nums[0]
break
log(f'Dividing {next_nums} and grabbing the remainder for the next test...')
_, remainder = next_nums[0] / next_nums[1]
next_nums = [next_nums[1], remainder]
log_unindent()
log(f'GCD is {found}')
return found⚠️NOTE️️️⚠️
The following is my attempt at explaining Euclid's algorithm after reading several online resources. You need an understanding of geometry and algebra before continuing.
Geometric explanation
Conceptually, you can think of Euclid's algorithm as recursively breaking off square chunks out of a rectangular area until it finds the smallest possible chunk that can be evenly copied to recreate the original rectangle. For example, imagine the numbers 21 and 6...
Since in 21x6, 6 is the smaller side, break off 6 from the 21 to get a 6x6 block...
Since in 15x6, 6 is the smaller side, break off 6 from the 15 to get a 6x6 block...
Since in 9x6, 6 is the smaller side, break off 6 from the 9 to get a 6x6 block...
Since in 3x6, 6 is the smaller side, break off 3 from the 6 to get a 3x3 block...
The remaining block is also 3x3 block. As such, the largest size that this entire rectangle can be constructed from is 3x3. The greatest common divisor is 3.
Notice how this is subtracting from the larger side at each step. Since division is iterative subtraction, this entire algorithm can be done using division. Starting from the very beginning...
Since in 21x6, 6 is the smaller side, break off as many blocks of 6 as possible from 21: (3 blocks of 6x6, with 3 remaining)...
Since in 3x6, 3 is the smaller side, break off as many blocks of 3 as possible from 6: (2 blocks of 3x3, with 0 remaining)...
Algebraic explanation
If 2 numbers are evenly divisible by some other number, then their sum/difference must also be divisible. For example, the numbers 21 and 6 are both divisible by 3:
Since they're both divisible by 3, if you were to add 18 and 6 together, the sum would also be divisible by 3...
Similarly, if you were to subtract 21 and 6, the difference would also be divisible by 3...
Even if you don't know what the divisor is, you can recursively break down the problem using the rules stated above. Imagine that you didn't know that 3 was the divisor for the previous example, but you know that some evenly divisible number existed...
Since you know that the if 21 and 6 are both divisible by d, their difference must also be divisible by d...
Now you know that 3 numbers are divisible by d: 21, 6, 15. Since you know that 15 and 6 are both divisible by d, their difference must also be divisible by d...
Now you know that 4 numbers are divisible by d: 21, 6, 15, and 9. Since you know that 15 and 9 are both divisible by d, their difference must also be divisible by d...
Now you know that 5 numbers are divisible by d: 21, 6, 15, 9, and 6. Since you know that 9 and 6 are both divisible by d, their difference must also be divisible by d...
Now you know that 6 numbers are divisible by d: 21, 6, 15, 9, 6, 3. Since you know that 9 and 6 are both divisible by d, their difference must also be divisible by d...
is 0, so the algorithm stops at this point -- d is 3.
⚠️NOTE️️️⚠️
Notice how for each subtraction step, the last 2 numbers are being chosen. When subtracting, the larger number goes first -- always subtract FROM the larger number.
You can plug 3 for d into the expressions above and each will evaluate to a whole number (no remainder). This algorithm is continually reducing the problem until it converges to the single greatest common divisor...
↩PREREQUISITES↩
Fractions are a way of representing numbers with fractional parts. The syntax for a fraction is , where the...
For example, if 4 parts make up a whole (denominator) and you have 9 of those parts (numerator), that's represented as .
You can think of fractions as unresolved integer division operations. That is, rather than performing the division, the division is left as-is and the entire thing is treated as a value. In the example above, performing results in 2R1, which is exactly the same value as represented by the fraction . As the circle diagram above shows, 2 wholes are available and 1 remaining part.
Since a fraction represent integer division, the same rules as integer division apply:
Recall that with integer division, if the dividend and the divisor have different sign then the quotient comes out negative. The same division rules apply to fractions. For example, ...
Recall that with division, the divisor (number being divided by) can't be 0. The same rule applies to fractions. For example, ...
If a fraction has ...
⚠️NOTE️️️⚠️
The term improper doesn't seem to mean anything bad? See http://mathforum.org/library/drmath/view/70437.html for reasoning as to why they're called proper vs improper.
⚠️NOTE️️️⚠️
I haven't seen it done a lot but the term quotient may be used to describe a fraction. Since a fraction is essentially an unresolved division operation, the fraction as a whole represents the quotient. As such, a fraction can be referred to as a quotient.
Two fractions are called equivalent fractions if they represent the same value. That is, the number of pieces may be different, but the overall value represented by the fraction is the same. For example, , , and are all considered equivalent fractions because they represent the same value:
Each fraction has different sized pieces, but the overall value covered by those pieces (the gray region) is the same.
↩PREREQUISITES↩
Of all the equivalent fractions that represent a value, one of those fractions represents that value in the smallest number of pieces possible. This fraction is called the simplified fraction. For the example above, is the simplified fraction for both and :
Algorithmically, a fraction is considered a simplified fraction if no common factors exist between its numerator and its denominator (other than 1). For example, for the fraction , the...
If a fraction isn't simplified, dividing the numerator and denominator by the highest common factor will make it simplified. In the example above, the highest common factor is 4. As such, dividing both the numerator and denominator by 4 will give the simplified fraction .
⚠️NOTE️️️⚠️
The process described above is getting the greatest common divisor / highest common factor for the 2 denominators, then dividing both denominators by it.
@log_decorator
def simplify(self: FractionNumber) -> FractionNumber:
# Sign is on the numerator
log(f'Simplifying {self}...')
log_indent()
log(f'Calculating GCD for ({self._numerator.magnitude}) and ({self._denominator.magnitude})...')
gcd = gcd_euclid(self._numerator.magnitude, self._denominator.magnitude)
log(f'GCD is {gcd}')
log(f'Dividing numerator ({self._numerator.magnitude}) by {gcd}...')
new_num, _ = self._numerator.magnitude / gcd
log(f'New numerator is {new_num}...')
log(f'Dividing denominator ({self._denominator.magnitude}) by {gcd}...')
new_den, _ = self._denominator.magnitude / gcd
log(f'New numerator is {new_den}...')
# Sign of fraction is on the numerator
if self.sign == Sign.NEGATIVE: # if original was negative, so will the simplified
res = FractionNumber(
IntegerNumber(Sign.NEGATIVE, new_num),
IntegerNumber(Sign.POSITIVE, new_den))
elif self.sign == Sign.POSITIVE: # if original was positive, so will the simplified
res = FractionNumber(
IntegerNumber(Sign.POSITIVE, new_num),
IntegerNumber(Sign.POSITIVE, new_den))
else: # if original was 0 (no sign), so will the simplified
res = FractionNumber(
IntegerNumber(None, new_num),
IntegerNumber(Sign.POSITIVE, new_den))
log_unindent()
log(f'{self} simplified to: {res}')
return res↩PREREQUISITES↩
Given a pair of fractions that have different denominators, you can find a pair of equivalent fractions that share a common denominator. For example, the fractions and ...
... have the following equivalent fractions that share a common denominator...
For any 2 fractions, the easiest algorithm to find equivalent fractions with common denominators is to multiply the numerator and denominator of each fraction by the denominator of the other fraction. So in the example above, the ...
⚠️NOTE️️️⚠️
If you already know fraction multiplication, you're effectively doing fraction multiplication here...
@staticmethod
@log_decorator
def common_denominator_naive(lhs: FractionNumber, rhs: FractionNumber) -> (FractionNumber, FractionNumber):
# Sign is only kept on the numerator, not the denominator
log(f'Getting {lhs} and {rhs} to common denominator equivalent fractions')
if lhs._denominator != rhs._denominator:
log_indent()
log(f'Calculating common denominator...')
common_denominator = rhs._denominator * lhs._denominator
log(f'{common_denominator}')
log(f'Calculating numerator for LHS ({lhs})...')
lhs_numerator = lhs._numerator * rhs._denominator
log(f'{lhs_numerator}')
log(f'Calculating numerator for RHS ({rhs})...')
rhs_numerator = rhs._numerator * lhs._denominator
log(f'{rhs_numerator}')
log_unindent()
lhs_equiv = FractionNumber(lhs_numerator, common_denominator)
rhs_equiv = FractionNumber(rhs_numerator, common_denominator)
log(f'Result: {lhs} -> {lhs_equiv}, {rhs} -> {rhs_equiv}')
return lhs_equiv, rhs_equiv
else:
log(f'Fractions already have a common denominator')
return lhs, rhsThe problem with the algorithm above is that it can result in fractions that have large numerators and denominators. For example, using the algorithm above to get the common denominator for and results in and .
A better approach that often leads to smaller numerators and denominators is to first figure out what the least common multiple between the denominators is (least common denominator). By figuring out what the least common denominator is, you can then work backwards to find the equivalent fractions that have those denominators:
So for the example above, the least common denominator for 15 and 10 is 30...
⚠️NOTE️️️⚠️
If you already know fraction multiplication, you're effectively doing fraction multiplication here...
@staticmethod
@log_decorator
def common_denominator_lcm(lhs: FractionNumber, rhs: FractionNumber) -> (FractionNumber, FractionNumber):
# Sign is only kept on the numerator, not the denominator
log(f'Getting {lhs} and {rhs} to common denominator equivalent fractions')
if lhs._denominator != rhs._denominator:
log_indent()
log(f'Calculating common denominator...')
common_denominator = lcm_prime_factorize(rhs._denominator.magnitude, lhs._denominator.magnitude)
common_denominator = IntegerNumber(Sign.POSITIVE, common_denominator)
log(f'{common_denominator}')
log(f'Calculating numerator for LHS ({lhs})...')
multiple, _ = common_denominator / lhs._denominator
lhs_numerator = lhs._numerator * multiple
log(f'{lhs_numerator}')
log(f'Calculating numerator for RHS ({rhs})...')
multiple, _ = common_denominator / rhs._denominator
rhs_numerator = rhs._numerator * multiple
log(f'{rhs_numerator}')
log_unindent()
lhs_equiv = FractionNumber(lhs_numerator, common_denominator)
rhs_equiv = FractionNumber(rhs_numerator, common_denominator)
log(f'Result: {lhs} -> {lhs_equiv}, {rhs} -> {rhs_equiv}')
return lhs_equiv, rhs_equiv
else:
log(f'Fractions already have a common denominator')
return lhs, rhs↩PREREQUISITES↩
Conceptually, you can think of fraction equality as comparing two fractions with similar sized parts to see if they have the same number of parts. That is, as long as the number of parts used to represent a whole (denominator) is the same between both fractions, testing to see if the fractions are equal is simply testing to see if the individual parts (numerators) are equal.
For example, the denominator for the fractions and is 4. Since the fractions have a common denominator, you can test if they're equal by applying integer equality to the numerators...
is computed as (false).
If the fractions being compared don't have a common denominator, you'll need to find equivalent fractions that do. The best way to do this is to use the least common denominator method. For example, before being able to compare and , they need to be converted to equivalent fractions that share a common denominator...
becomes
becomes
is computed as (false).
The way to perform this algorithm via code is as follows...
@log_decorator
def __eq__(lhs: FractionNumber, rhs: FractionNumber) -> bool:
log(f'Equality testing {lhs} and {rhs}...')
log_indent()
# Sign is only kept on the numerator, not the denominator
log(f'Checking if denominators are the same...')
if lhs._denominator != rhs._denominator:
log(f'Not same -- finding equivalent fractions with common denominator...')
log_indent()
log(f'Calculating common denominator...')
denominator = rhs._denominator * lhs._denominator
log(f'{denominator}')
log(f'Scaling numerator for {lhs} so denominator becomes {denominator}...')
lhs_numerator = lhs._numerator * rhs._denominator
log(f'Numerator: {lhs_numerator} Denominator: {denominator}')
log(f'Scaling numerator for {rhs} so denominator becomes {denominator}...')
rhs_numerator = rhs._numerator * lhs._denominator
log(f'Numerator: {rhs_numerator} Denominator: {denominator}')
log_unindent()
else:
log(f'Same')
lhs_numerator = lhs._numerator
rhs_numerator = rhs._numerator
denominator = rhs._denominator
log(f'Testing {lhs_numerator} == {rhs_numerator}...')
ret = lhs_numerator == rhs_numerator
log(f'{ret}')
return ret↩PREREQUISITES↩
Conceptually, you can think of fraction less than as comparing two fractions with similar sized parts to see which has less parts. That is, as long as the number of parts used to represent a whole (denominator) is the same between both fractions, testing to see which fraction is less is simply testing to see which has less individual parts (numerators).
For example, the denominator for the fractions and is 4. Since the fractions have a common denominator, you can test to see which is less by applying integer less than to the numerators...
is computed as (true).
If the fractions being compared don't have a common denominator, you'll need to find equivalent fractions that do. The best way to do this is to use the least common denominator method. For example, before being able to compare and , they need to be converted to equivalent fractions that share a common denominator...
becomes
becomes
is computed as (false).
The way to perform this algorithm via code is as follows...
@log_decorator
def __lt__(lhs: FractionNumber, rhs: FractionNumber) -> bool:
log(f'Less than testing {lhs} and {rhs}...')
log_indent()
# Sign is only kept on the numerator, not the denominator
log(f'Checking if denominators are the same...')
if lhs._denominator != rhs._denominator:
log(f'Not same -- finding equivalent fractions with common denominator...')
log_indent()
log(f'Calculating common denominator...')
denominator = rhs._denominator * lhs._denominator
log(f'{denominator}')
log(f'Scaling numerator for {lhs} so denominator becomes {denominator}...')
lhs_numerator = lhs._numerator * rhs._denominator
log(f'Numerator: {lhs_numerator} Denominator: {denominator}')
log(f'Scaling numerator for {rhs} so denominator becomes {denominator}...')
rhs_numerator = rhs._numerator * lhs._denominator
log(f'Numerator: {rhs_numerator} Denominator: {denominator}')
log_unindent()
else:
log(f'Same')
lhs_numerator = lhs._numerator
rhs_numerator = rhs._numerator
denominator = rhs._denominator
log(f'Testing {lhs_numerator} < {rhs_numerator}...')
ret = lhs_numerator < rhs_numerator
log(f'{ret}')
return ret↩PREREQUISITES↩
Conceptually, you can think of fraction greater than as comparing two fractions with similar sized parts to see which has more parts. That is, as long as the number of parts used to represent a whole (denominator) is the same between both fractions, testing to see which fraction is more is simply testing to see which has more individual parts (numerators).
For example, the denominator for the fractions and is 4. Since the fractions have a common denominator, you can test to see which is more by applying integer less than to the numerators...
is computed as (false).
If the fractions being compared don't have a common denominator, you'll need to find equivalent fractions that do. The best way to do this is to use the least common denominator method. For example, before being able to compare and , they need to be converted to equivalent fractions that share a common denominator...
becomes
becomes
is computed as (true).
The way to perform this algorithm via code is as follows...
@log_decorator
def __gt__(lhs: FractionNumber, rhs: FractionNumber) -> bool:
log(f'Greater than testing {lhs} and {rhs}...')
log_indent()
# Sign is only kept on the numerator, not the denominator
log(f'Checking if denominators are the same...')
if lhs._denominator != rhs._denominator:
log(f'Not same -- finding equivalent fractions with common denominator...')
log_indent()
log(f'Calculating common denominator...')
denominator = rhs._denominator * lhs._denominator
log(f'{denominator}')
log(f'Scaling numerator for {lhs} so denominator becomes {denominator}...')
lhs_numerator = lhs._numerator * rhs._denominator
log(f'Numerator: {lhs_numerator} Denominator: {denominator}')
log(f'Scaling numerator for {rhs} so denominator becomes {denominator}...')
rhs_numerator = rhs._numerator * lhs._denominator
log(f'Numerator: {rhs_numerator} Denominator: {denominator}')
log_unindent()
else:
log(f'Same')
lhs_numerator = lhs._numerator
rhs_numerator = rhs._numerator
denominator = rhs._denominator
log(f'Testing {lhs_numerator} > {rhs_numerator}...')
ret = lhs_numerator > rhs_numerator
log(f'{ret}')
return ret↩PREREQUISITES↩
Conceptually, you can think of fraction addition as adding together parts. That is, as long as the number of parts used to represent a whole (denominator) is the same between both fractions, adding them together is simply adding together the individual parts (numerators).
For example, the denominator for the fractions and is 4. Since the fractions have a common denominator, you can add them together by adding the numerators while keeping the denominator...
is
Treat the sign of the fraction as if it were on the numerator. For example, adding and results in -- results in , so the resulting fraction is .
If the fraction being added don't have a common denominator, you'll need to find equivalent fractions that do. The best way to do this is to use the least common denominator method. For example, before being able to add and , they need to be converted to equivalent fractions that share a common denominator...
becomes
becomes
is
@log_decorator
def __add__(lhs: FractionNumber, rhs: FractionNumber) -> FractionNumber:
# Sign is only kept on the numerator, not the denominator
log(f'Adding {lhs} and {rhs}...')
log_indent()
log(f'Converting {lhs} and {rhs} to equivalent fractions with least common denominator...')
lhs, rhs = FractionNumber.common_denominator_lcm(lhs, rhs)
log(f'Equivalent fractions: {lhs} and {rhs}')
log(f'Adding numerators of {lhs} and {rhs}...')
res = FractionNumber(lhs._numerator + rhs._numerator, lhs._denominator)
log_unindent()
log(f'Result: {res}')
return res↩PREREQUISITES↩
Conceptually, you can think of fraction subtraction as subtracting parts. That is, as long as the number of parts used to represent a whole (denominator) is the same between both fractions, subtracting them is simply subtracting the individual parts (numerators).
For example, the denominator for the fractions and is 4. Since the fractions have a common denominator, you can subtract them by subtracting the numerators while keeping the denominator...
is
Treat the sign of the fraction as if it were on the numerator. For example, subtracting and results in -- results in , so the resulting fraction is .
If the fraction being subtracted don't have a common denominator, you'll need to find equivalent fractions that do. The best way to do this is to use the least common denominator method. For example, before being able to subtract and , they need to be converted to equivalent fractions that share a common denominator...
becomes
becomes
is
@log_decorator
def __sub__(lhs: FractionNumber, rhs: FractionNumber) -> FractionNumber:
# Sign is only kept on the numerator, not the denominator
log(f'Subtracting {lhs} and {rhs}...')
log(f'Converting {lhs} and {rhs} to equivalent fractions with least common denominator...')
log(f'Converting {lhs} and {rhs} to equivalent fractions with least common denominator...')
lhs, rhs = FractionNumber.common_denominator_lcm(lhs, rhs)
log(f'Equivalent fractions: {lhs} and {rhs}')
log(f'Subtracting numerators of {lhs} and {rhs}...')
res = FractionNumber(lhs._numerator - rhs._numerator, lhs._denominator)
log_unindent()
log(f'Result: {res}')
return res↩PREREQUISITES↩
Conceptually, you can think of fraction multiplication as an extension to integer multiplication. In integer multiplication, you're repeatedly adding the same value for a certain number of iterations. For example, in , the number 4 is being added for 2 iterations: .
Fraction multiplication follows the same concept but may also involve the adding of a fractional value. For example, imagine . Recall that fractions can be thought of as unresolved integer division -- the fraction is just another way of saying .
If you perform , the quotient would be ...
As such, is just another way of saying 4 should be added for 2 and a half iterations: .
⚠️NOTE️️️⚠️
2 is half of 4. That's why there's a 2 as the last addition.
The human understandable algorithm for fraction multiplication relies on two ideas...
Any fraction can be broken down as repetitive fraction addition of a single piece. For example, the fraction can be written as .
Since multiplication is repetitive addition, the above addition can be written as .
If you have two fractions that are both single pieces (both have 1 as their numerator), the algorithm for multiplying them together is to keep the 1 in the numerator spot but multiply the denominators together. For example, is .
To understand why this works, visualize the fractions as the slicing of a whole:
Start with a whole...
Take of that whole...
Take of that ...
The result is 1 of 6 parts: , exactly the same as what you would get if you were to keep the 1 in the numerator spot but multiply the denominators together (the algorithm).
Any two fractions can be multiplied together by...
Idea 1 applies to step 4 because the result of step 2 will always be a single piece and the result of step 3 will always be an integer.
For example, to perform , begin by breaking each fraction (idea 1): .
Then, multiply the integers together:
⚠️NOTE️️️⚠️
This is possible because multiplication is commutative -- numbers can be multiplied together in any order and the result will always be the same.
Then, multiply the single piece fractions together (idea 2):
⚠️NOTE️️️⚠️
This is possible because multiplication is commutative -- numbers can be multiplied together in any order and the result will always be the same.
Finally, multiply the single piece fraction with the integer (idea 1):
If you look closely at the example above, you may notice that the final product is the product of the numerators and the product of the denominators. For example, in , the ...
... resulting in the final product .
This is the accepted algorithm for multiplying any 2 fractions together. The product of fractions is the product of their numerators over the product of their denominators.
@log_decorator
def __mul__(lhs: FractionNumber, rhs: FractionNumber) -> FractionNumber:
# Sign is only kept on the numerator, not the denominator
log(f'Multiplying {lhs} and {rhs}')
log_indent()
log(f'Multiplying numerators {lhs._numerator} and {rhs._numerator}...')
numerator = lhs._numerator * rhs._numerator
log(f'Multiplying denominators {lhs._denominator} and {rhs._denominator}...')
denominator = lhs._denominator * rhs._denominator
res = FractionNumber(numerator, denominator)
log_unindent()
log(f'Result: {res}')
return res⚠️NOTE️️️⚠️
If you understand algebra, the reasoning for why the above algorithm works is available at http://mathforum.org/library/drmath/view/63841.html. It uses the same concept of breaking down fractions into single pieces.
↩PREREQUISITES↩
The reciprocal of a fraction is when you take that fraction and flip its numerator and denominator. For example, the reciprocal of is .
When you multiply a fraction by its reciprocal, you will always end up with a whole. For example, is .
@log_decorator
def reciprocal(self: FractionNumber) -> FractionNumber:
# Sign is on the numerator
log(f'Getting reciprocal of {self}')
res = FractionNumber(self._denominator, self._numerator)
log(f'Result: {res}')
return res↩PREREQUISITES↩
Any fraction can be written out as a mixed number, where the wholes are written as a normal integer and the remaining portion is written as a fraction. Recall that fractions can be thought of as unresolved integer division. For example, the fraction is equivalent to the division .
If you were to perform , the quotient would be -- 3 wholes with 3 remaining pieces...
As such, can be written as the mixed number .
⚠️NOTE️️️⚠️
Don't get confused -- the mixed number means , it does not mean (multiplication).
To convert a...
fraction to a mixed number, divide the numerator and the denominator using integer division.
.
mixed number to a fraction, convert the wholes to a fraction then add the remaining fraction.
.
↩PREREQUISITES↩
Conceptually, you can think of fraction division as an extension to integer division. In integer division, you're repeatedly subtracting the some value until it reaches 0. For example, in , the number 8 is subtracted for 4 iterations to reach 0: is 0.
Fraction division follows the same concept but may also involve the subtraction of a fractional value. For example, imagine . You can successfully subtract for 5 iterations before the value becomes smaller than but larger than 0...
is .
In each of the iterations above, is being subtracted in its entirety. For the final smaller value of , you need to subtract by some smaller portion of . That is, what fraction of would be needed to get rid of the remaining value of ...
results in .
You need of to get ...
results in , which simplifies to .
As such, the number of iterations you need to subtract by for 8 to reach 0 is .
⚠️NOTE️️️⚠️
The above is a mixed number, not multiplication.
The algorithm used for dividing fractions is to simply take the first fraction and multiply it by the reciprocal of the second fraction. For the example above, would be computed as .
results in , which is exactly the same as the iterations that was reasoned above...
@log_decorator
def __truediv__(lhs: FractionNumber, rhs: FractionNumber) -> FractionNumber:
# Sign is only kept on the numerator, not the denominator
log(f'Dividing {lhs} and {rhs}')
res = FractionNumber(lhs._numerator * rhs._denominator, lhs._denominator * rhs._numerator)
log(f'Result: {res}')
return res⚠️NOTE️️️⚠️
If you understand algebra, the reasoning for why the above algorithm works is available at https://math.stackexchange.com/a/71173...
Write as .
Suppose you wanted to clear the denominator of this compound fraction. You could try multiplication by , but you'll have to multiply the top and the bottom of the fraction to avoid changing it. So, you end up with
↩PREREQUISITES↩
Fraction word conversion is the process of taking a fraction number and converting it to words. The algorithm used by humans to convert a fraction number to words is as follows:
Begin by converting the sign to a word. If the number is ...
⚠️NOTE️️️⚠️
Then, ...
For example, the number...
The way to perform this algorithm via code is as follows...
@log_decorator
def to_words(self: FractionNumber) -> str:
log(f'Converting {self}...')
output = ''
if self.sign == Sign.NEGATIVE:
output += 'negative '
output += self.numerator.to_words()
output += ' over '
output += self.denominator.to_words()
log_unindent()
log(f'{output}')
return output.lstrip()There's a slightly varied form of the algorithm above that's also acceptable:
Begin by writing out the words "quotient of" or "ratio of". Then, if the number ...
⚠️NOTE️️️⚠️
Then, ...
For example, the number...
⚠️NOTE️️️⚠️
Recall that "quotient of" is also used to represent a division operation. This is fine because recall that a fraction number is technically an unresolved integer division operation.
↩PREREQUISITES↩
A decimal number is another way of representing a mixed number where the denominator of the fraction is 1 followed by 0s. For example, ...
The period placed in between the whole and the fraction is referred to as a decimal point. The number to the ...
⚠️NOTE️️️⚠️
You can consider the sign and the whole part as the integer part. The term integer part is used in the subsections below.
A mixed number can be converted to a decimal number so long as it has a qualifying denominator. A qualifying denominator starts with 1 followed by 0s. For example, has a qualifying denominator but doesn't.
If the denominator doesn't qualify, the mixed number may still be convertible so long as an equivalent fraction exists that does have a qualifying denominator. In the previous example, is an equivalent fraction to .
To convert a mixed number into a decimal number ...
For example, converting to a decimal number results in 2.009.
⚠️NOTE️️️⚠️
Steps for conversion are as follows:
Fraction conversion subsections below provide more in-depth discussion on how to conversions. However, those subsections require that you know how to do basic decimal number arithmetic before hand.
To convert a decimal number to a mixed number...
For example, converting 2.009 to a mixed number results in
⚠️NOTE️️️⚠️
Steps for conversion are as follows:
Fraction conversion subsections below provide more in-depth discussion on how to conversions. However, those subsections require that you know how to do basic decimal number arithmetic before hand.
↩PREREQUISITES↩
Conceptually, you can think of decimal equality the same as fraction equality where the fraction is represented as a mixed number. However, rather than converting both numbers to a fraction and performing fraction quality, a quick series of tests on the decimal numbers themselves can determine equality:
If all tests above pass, the decimal numbers are equal.
For example, the numbers -195.26 and 195.36 are not equal...
- 1 9 5 . 2 6
x | | | x |
+ 1 9 5 . 3 6
... while the numbers -195.26 and -195.26 are equal...
- 1 9 5 . 2 6
| | | | | |
- 1 9 5 . 2 6
The way to perform this algorithm via code is as follows...
⚠️NOTE️️️⚠️
The first listing is the main DecimalNumber code, while the second listing is the code for fractional part called by the main DecimalNumber code.
@log_decorator
def __eq__(lhs: DecimalNumber, rhs: DecimalNumber) -> bool:
class FailedTestException(Exception):
pass
log(f'Equality testing {lhs} and {rhs}...')
log_indent()
try:
log(f'Testing integer...')
int_eq = IntegerNumber(lhs.sign, lhs.whole) == IntegerNumber(rhs.sign, rhs.whole)
if not int_eq:
raise FailedTestException()
log(f'Equal')
log(f'Testing fractional...')
fractional_eq = lhs.fractional == rhs.fractional
if not fractional_eq:
raise FailedTestException()
log(f'Equal')
ret = True
except FailedTestException:
log(f'Not equal')
ret = False
log_unindent()
log(f'{ret}')
return ret@log_decorator
def __eq__(lhs: FractionalNumber, rhs: FractionalNumber) -> bool:
if not isinstance(rhs, FractionalNumber):
raise Exception()
log(f'Equality testing {lhs} and {rhs}...')
log_indent()
ret = lhs.digits == rhs.digits
log_unindent()
log(f'{ret}')
return ret↩PREREQUISITES↩
Conceptually, you can think of decimal less than the same as fraction less than where the fraction is represented as a mixed number. However, rather than converting both numbers to a fraction and performing fraction less than, a quick series of tests on the decimal numbers themselves can determine less than:
Check the integer parts...
If the integer parts are integer less than, then the decimal numbers themselves will be decimal less than. For example, any decimal number with an integer part of 5 will always be less than any decimal number with an integer part of 6...
If the integer parts are equal, go to step 2.
Otherwise, stop. The decimal numbers are not less than.
Check the fractional parts...
If the fractional parts are less than, the decimal numbers are less than. The process of testing the fractional parts is similar to whole number less than, except the order in which positions are tested is reversed (index 0 is the most significant digit, index 1 is the second digit, index 2 is the third most significant digit, ...). For example, a fractional part of 01 is less than a fractional part of 1...
For example, to test if 312.02 < 312.12:
312.02 < 312.12 is true.
The way to perform this algorithm via code is as follows...
⚠️NOTE️️️⚠️
The first listing is the main DecimalNumber code, while the second listing is the code for fractional part called by the main DecimalNumber code.
@log_decorator
def __lt__(lhs: DecimalNumber, rhs: DecimalNumber) -> bool:
class PassedTestException(Exception):
pass
class FailedTestException(Exception):
pass
log(f'Less than testing {lhs} and {rhs}...')
log_indent()
try:
log(f'Testing integer...')
int_lt = IntegerNumber(lhs.sign, lhs.whole) < IntegerNumber(rhs.sign, rhs.whole)
if int_lt:
raise PassedTestException()
int_eq = IntegerNumber(lhs.sign, lhs.whole) == IntegerNumber(rhs.sign, rhs.whole)
if not int_eq:
raise FailedTestException()
log(f'Equal')
log(f'Testing fractional...')
fractional_lt = lhs.fractional < rhs.fractional
if fractional_lt:
raise PassedTestException()
fractional_eq = lhs.fractional == rhs.fractional
if not fractional_eq:
raise FailedTestException()
log(f'Equal')
ret = False
except PassedTestException:
log(f'Less')
ret = True
except FailedTestException:
log(f'Not less or equal')
ret = False
log_unindent()
log(f'{ret}')
return ret@log_decorator
def __lt__(lhs: FractionalNumber, rhs: FractionalNumber) -> bool:
if not isinstance(rhs, FractionalNumber):
raise Exception()
log(f'Less than testing {lhs} and {rhs}...')
log_indent()
count = max(len(lhs.digits), len(rhs.digits))
for pos in range(0, count): # from smallest to largest component
log(f'Test digits {lhs[pos]} and {rhs[pos]}...')
if lhs[pos] > rhs[pos]:
log(f'{lhs[pos]} > {rhs[pos]} -- {lhs} is NOT less than {rhs}, it is greater than')
return False
elif lhs[pos] < rhs[pos]:
log(f'{lhs[pos]} < {rhs[pos]} -- {lhs} is less than {rhs}')
return True
else:
log(f'{lhs[pos]} == {rhs[pos]} -- continuing testing')
log(f'No more digits to test -- {lhs} is NOT less than {rhs}, it is equal')
return False↩PREREQUISITES↩
Conceptually, you can think of decimal greater than the same as fraction greater than where the fraction is represented as a mixed number. However, rather than converting both numbers to a fraction and performing fraction less than, a quick series of tests on the decimal numbers themselves can determine greater than:
Check the integer parts...
If the integer parts are integer greater than, then the decimal numbers themselves will be decimal greater than. For example, any decimal number with an integer part of 6 will always be greater than any decimal number with an integer part of 5...
If the integer parts are equal, go to step 2.
Otherwise, stop. The decimal numbers are not less than.
Check the fractional parts...
If the fractional parts are greater than, the decimal numbers are greater than. The process of testing the fractional parts is similar to whole number greater than, except the order in which positions are tested is reversed (index 0 is the most significant digit, index 1 is the second digit, index 2 is the third most significant digit, ...). For example, a fractional part of 1 is greater than a fractional part of 01...
For example, to test if 312.12 < 312.02:
312.12 > 312.02 is true.
The way to perform this algorithm via code is as follows...
⚠️NOTE️️️⚠️
The first listing is the main DecimalNumber code, while the second listing is the code for fractional part called by the main DecimalNumber code.
@log_decorator
def __gt__(lhs: DecimalNumber, rhs: DecimalNumber) -> bool:
class PassedTestException(Exception):
pass
class FailedTestException(Exception):
pass
log(f'Greater than testing {lhs} and {rhs}...')
log_indent()
try:
log(f'Testing integer...')
int_lt = IntegerNumber(lhs.sign, lhs.whole) > IntegerNumber(rhs.sign, rhs.whole)
if int_lt:
raise PassedTestException()
int_eq = IntegerNumber(lhs.sign, lhs.whole) == IntegerNumber(rhs.sign, rhs.whole)
if not int_eq:
raise FailedTestException()
log(f'Equal')
log(f'Testing fractional...')
fractional_gt = lhs.fractional > rhs.fractional
if fractional_gt:
raise PassedTestException()
fractional_eq = lhs.fractional == rhs.fractional
if not fractional_eq:
raise FailedTestException()
log(f'Equal')
ret = False
except PassedTestException:
log(f'Greater')
ret = True
except FailedTestException:
log(f'Not greater or equal')
ret = False
log_unindent()
log(f'{ret}')
return ret@log_decorator
def __gt__(lhs: FractionalNumber, rhs: FractionalNumber) -> bool:
if not isinstance(rhs, FractionalNumber):
raise Exception()
log(f'Greater than testing {lhs} and {rhs}...')
log_indent()
count = max(len(lhs.digits), len(rhs.digits))
for pos in range(0, count): # from smallest to largest component
log(f'Test digits {lhs[pos]} and {rhs[pos]}...')
if lhs[pos] > rhs[pos]:
log(f'{lhs[pos]} > {rhs[pos]} -- {lhs} is greater than {rhs}')
return True
elif lhs[pos] < rhs[pos]:
log(f'{lhs[pos]} < {rhs[pos]} -- {lhs} is NOT greater than {rhs}, it is less than')
return False
else:
log(f'{lhs[pos]} == {rhs[pos]} -- continuing testing')
log(f'No more digits to test -- {lhs} is NOT greater than {rhs}, it is equal')
return False↩PREREQUISITES↩
Decimal number word conversion is the process of taking a decimal number and converting it to words. The algorithm used by humans to convert a decimal number to words is as follows:
Begin by converting the sign to a word. If the number is ...
⚠️NOTE️️️⚠️
Then, if the number isn't 0.0, ...
Then, count the number of digits in the fractional and write out the matching word...
| Count | Word |
|---|---|
| 1 | tenth |
| 2 | hundredth |
| 3 | thousandth |
| 4 | ten-thousandth |
| 5 | hundred-thousandth |
| 6 | millionth |
| 7 | ten-millionth |
| 8 | hundred-millionth |
| ... | ... |
If the fractional is more than 1 piece, append the letter s to the number being written out. For example, ...
For example, the number...
The way to perform this algorithm via code is as follows...
@log_decorator
def to_words(self: DecimalNumber) -> str:
fractional_len_to_suffixes = {
1: 'tenth',
2: 'hundredth',
3: 'thousandth',
4: 'ten-thousandth',
5: 'hundred-thousandth',
6: 'millionth',
7: 'ten-millionth',
8: 'hundred-millionth',
9: 'billionth',
10: 'ten-billionth',
11: 'hundred-billionth',
12: 'trillionth',
13: 'ten-trillionth',
14: 'hundred-trillionth',
15: 'quadrillionth',
16: 'ten-quadrillionth',
17: 'hundred-quadillionth',
18: 'quintillionth',
19: 'ten-quintillionth',
20: 'hundred-quintillionth',
}
log(f'Converting {self}...')
log_indent()
log(f'Converting whole portion to words...')
whole_words = self.whole.to_words()
log(f'Whole as words: {whole_words}')
log(f'Converting fractional portion to words...')
fractional_words = WholeNumber.from_str(str(self.fractional)).to_words()
log(f'fractional as words: {fractional_words}')
output = ''
if self.whole == WholeNumber.from_str('0') and self.fractional == FractionalNumber.from_str('0'):
output += 'zero'
else:
if self.sign == Sign.NEGATIVE:
output += 'negative '
if self.whole != WholeNumber.from_str('0'):
output += whole_words
if self.whole != WholeNumber.from_str('0') and self.fractional != FractionalNumber.from_str('0'):
output += ' and '
if self.fractional != FractionalNumber.from_str('0'):
output += fractional_words
suffix = fractional_len_to_suffixes[len(self.fractional.digits)]
if suffix is None:
raise Exception('Fractional too large')
log(f'Fractional suffix: {suffix}')
if self.fractional != FractionalNumber.from_str('0'): # pluralize suffix if more than 1
suffix += 's'
output += ' ' + suffix
log_unindent()
log(f'{output}')
return output.strip()↩PREREQUISITES↩
Conceptually, you can think of decimal addition the same as fraction addition where the fraction is represented as a mixed number. However, rather than converting both numbers to a fraction and performing fraction addition, a more straight-forward algorithm exists.
The algorithms used by humans to perform decimal addition is essentially the same as vertical addition for whole numbers. To perform vertical addition for decimal numbers: stack the numbers on top of each other aligned by position and add each digit, carrying over when an overflow occurs. For example, adding 123.45 to 1.1...
⚠️NOTE️️️⚠️
Recall that empty positions are 0, so you can think of the 1.1 in the vertical addition example above as 001.10 .
This works for the fractional part just as it does for the whole part because the overflow from the fractional part bleeds into the whole part. For example, adding to results in the mixed number . That same operation done through vertical addition with equivalent decimal numbers produces the same result...
Notice how if you were to remove the decimal point from the decimal numbers being added, the result would be the same as adding them with the decimal point and removing the decimal point from the result. For the 123.45 + 1.1 example above, ...
adding with decimal point...
adding without decimal point...
The decimal point can simply be placed in after the addition takes place: 12455 ⟶ 124.55.
Knowing this, a new vertical addition algorithm / implementation isn't needed. The inputs can be massaged (remove decimal point) so they work with the existing algorithm and the output can be massaged back (place in decimal point).
Since decimal numbers also have a sign, vertical addition can't be used if either number is negative. Rather, integer addition needs to be used. Integer addition makes use of whole number vertical addition but also accounts for the sign.
⚠️NOTE️️️⚠️
If you know about decimal multiplication and decimal division already, you're essentially counting the number of fractional digits for the number that has more fractional digits, then multiplying each number by 10 for that many iterations.
The results are guaranteed to have no fractional part, so you can use integer addition on them.
Once you've added, divide the result by 10 for the same number of iterations to get back the result as a decimal number.
The result is 124.55.
Multiplying by 10 shifts the decimal point to the right. Dividing by 10 shifts the decimal point to the left.
The way to perform this algorithm via code is as follows...
@log_decorator
def __add__(lhs: DecimalNumber, rhs: DecimalNumber) -> DecimalNumber:
log(f'Adding {lhs} and {rhs}...')
log_indent()
adjust_len = max(
len(lhs.fractional.digits),
len(rhs.fractional.digits)
)
log(f'Generating mock integer number for {lhs}...')
lhs_extra_0s = adjust_len - len(lhs.fractional.digits)
lhs_combined_digits = lhs.fractional.digits + lhs.whole.digits
lhs_combined_digits[0:0] = [Digit(0)] * lhs_extra_0s
mock_self = IntegerNumber(lhs.sign, WholeNumber(lhs_combined_digits))
log(f'{mock_self}')
log(f'Generating mock integer number for {rhs}...')
rhs_extra_0s = adjust_len - len(rhs.fractional.digits)
rhs_combined_digits = rhs.fractional.digits + rhs.whole.digits
rhs_combined_digits[0:0] = [Digit(0)] * rhs_extra_0s
mock_other = IntegerNumber(rhs.sign, WholeNumber(rhs_combined_digits))
log(f'{mock_other}')
log(f'Performing {mock_self} + {mock_other}...')
mock_ret = mock_self + mock_other
log(f'{mock_ret}')
log(f'Unmocking {mock_ret} back to decimal...')
ret_sign = mock_ret.sign
ret_fractional_digits = [mock_ret.magnitude[i] for i in range(0, adjust_len)]
ret_whole_digits = [mock_ret.magnitude[i] for i in range(adjust_len, len(mock_ret.magnitude.digits))]
ret = DecimalNumber(ret_sign, WholeNumber(ret_whole_digits), FractionalNumber(ret_fractional_digits))
log(f'{ret}')
log_unindent()
log(f'{ret}')
return retConceptually, you can think of decimal subtraction the same as fraction subtraction where the fraction is represented as a mixed number. However, rather than converting both numbers to a fraction and performing fraction subtraction, a more straight-forward algorithm exists.
The algorithms used by humans to perform decimal subtraction is essentially the same as vertical subtraction for whole numbers. To perform vertical subtraction for decimal numbers: stack the numbers on top of each other aligned by position and subtract each digit, borrowing when necessary. For example, subtracting 1.1 from 123.45...
⚠️NOTE️️️⚠️
Recall that empty positions are 0, so you can think of the 1.1 in the vertical subtracting example above as 001.10 .
This works for the fractional part just as it does for the whole part because the carry over for the fractional part comes from the whole part. For example, subtracting from the mixed number results in . That same operation done through vertical subtraction with equivalent decimal numbers produces the same result...
Notice how if you were to remove the decimal point from the decimal numbers being subtracted, the result would be the same as subtracting them with the decimal point and removing the decimal point from the result. For the 123.45 - 1.1 example above, ...
subtracting with decimal point...
subtracting without decimal point...
The decimal point can simply be placed in after the subtraction takes place: 12235 ⟶ 122.35.
Knowing this, a new vertical subtraction algorithm / implementation isn't needed. The inputs can be massaged (remove decimal point) so they work with the existing algorithm and the output can be massaged back (place in decimal point).
Since decimal numbers also have a sign, vertical subtraction can't be used if either number is negative. Rather, integer subtraction needs to be used. Integer subtraction makes use of whole number vertical subtraction but also accounts for the sign.
⚠️NOTE️️️⚠️
If you know about decimal multiplication and decimal division already, you're essentially counting the number of fractional digits for the number that has more fractional digits, then multiplying each number by 10 for that many iterations.
The results are guaranteed to have no fractional part, so you can use integer subtraction on them.
Once you've subtracted, divide the result by 10 for the same number of iterations to get back the result as a decimal number.
The result is 122.35.
Multiplying by 10 shifts the decimal point to the right. Dividing by 10 shifts the decimal point to the left.
The way to perform this algorithm via code is as follows...
@log_decorator
def __sub__(lhs: DecimalNumber, rhs: DecimalNumber) -> DecimalNumber:
log(f'Subtracting {lhs} and {rhs}...')
log_indent()
adjust_len = max(
len(lhs.fractional.digits),
len(rhs.fractional.digits)
)
log(f'Generating mock integer number for {lhs}...')
lhs_extra_0s = adjust_len - len(lhs.fractional.digits)
lhs_combined_digits = lhs.fractional.digits + lhs.whole.digits
lhs_combined_digits[0:0] = [Digit(0)] * lhs_extra_0s
mock_self = IntegerNumber(lhs.sign, WholeNumber(lhs_combined_digits))
log(f'{mock_self}')
log(f'Generating mock integer number for {rhs}...')
rhs_extra_0s = adjust_len - len(rhs.fractional.digits)
rhs_combined_digits = rhs.fractional.digits + rhs.whole.digits
rhs_combined_digits[0:0] = [Digit(0)] * rhs_extra_0s
mock_other = IntegerNumber(rhs.sign, WholeNumber(rhs_combined_digits))
log(f'{mock_other}')
log(f'Performing {mock_self} - {mock_other}...')
mock_ret = mock_self - mock_other
log(f'{mock_ret}')
log(f'Unmocking {mock_ret} back to decimal...')
ret_sign = mock_ret.sign
ret_fractional_digits = [mock_ret.magnitude[i] for i in range(0, adjust_len)]
ret_whole_digits = [mock_ret.magnitude[i] for i in range(adjust_len, len(mock_ret.magnitude.digits))]
ret = DecimalNumber(ret_sign, WholeNumber(ret_whole_digits), FractionalNumber(ret_fractional_digits))
log(f'{ret}')
log_unindent()
log(f'{ret}')
return ret↩PREREQUISITES↩
Conceptually, you can think of decimal multiplication the same as fraction multiplication where the fraction is represented as a mixed number. However, rather than converting both numbers to a fraction and performing fraction multiplication, a more straight-forward algorithm exists.
The algorithms used by humans to perform decimal multiplication is almost the same as vertical multiplication for whole numbers. To perform vertical multiplication for decimal numbers:
For example, to multiply 123.45 by 1.1, perform the multiplication without the decimal points...
Then, place in the decimal point. Since 123.45 has 2 fractional digits and 1.1 has 1 fractional digit (2 + 1 = 3), the decimal point is placed in just before the digit at the 3rd position (starting from the left)...
The vertical multiplication algorithm works because the ideas behind whole number multiplication are similar to the ideas behind decimal number multiplication:
Numbers represented in place-value notation can be broken down into single digit components -- the place of each digit in the number represents some portion of that number's value. For example, the number 123.45 can be broken down as ...
The multiplication of any two single digit components from rule 1 is equivalent to individually multiplying the single digit components and individually multiplying the fractional part, then multiplying the results together. For example, ...
⚠️NOTE️️️⚠️
The numerator and denominator in the fractional parts both start with 1 followed by zero or more 0s. These fractional parts can be done quickly using a trick. If...
both numerators are followed by 0s, the resulting fraction will have as many 0s as both fractions.
e.g. * =
both denominators are followed by 0s, the resulting denominator will have as many 0s as both fractions.
e.g. * =
a numerator and a denominator both are followed by 0s, count the number of 0s in the one with less 0s and remove that many 0s from the other.
e.g. * =
e.g. * =
Recall that multiplication can be thought of as repetitive addition. However, unlike with whole numbers, decimal numbers have a fractional part that need to be accounted for. That fractional part represents a fraction of the number being iteratively added.
For example, 8 * 2.5 = 20 produces the same result as 8 + 8 + 8 * = 20. 8 is added for 2 iterations, and then half of 8 is added (0.5 is equivalent to which simplifies to ).
That same result (20) could have been produced from any number of different addition combinations:
Given these ideas, any two numbers can be multiplied by ...
For example, to multiply 123.45 by 1.1, begin by enumerating the single digit components of each number (idea 1)...
123.45 breaks down to...
1.1 breaks down to...
Then, multiply the single digit components of 123.45 with the single digit components of 1.1...
multiply each single digit components of 123.45 by the 1.0 component of 1.1:
multiply each single digit components of 123.45 by the 0.1 component of 1.1:
Then, add the result of the multiplications in the previous step:
Notice how in the example, the multiplication of the least significant single digit component from both inputs produces the least significant single digit component in the output. That is, ...
The number of digits in the fractional part of the output will always be the total number of digits in the fractional parts of both inputs. The first input (123.45) has 2 fractional digits and the second input (1.1) has 1 fractional digit, so the output (135.795) is guaranteed to have 3 fractional digits.
This is the intuition behind the post-processing step in vertical multiplication where the decimal point is added back in:
For example, to multiply 123.45 by 1.1, perform the multiplication without the decimal points...
Then, place in the decimal point. Since 123.45 has 2 fractional digits and 1.1 has 1 fractional digit (2 + 1 = 3), the decimal point is placed in just before the digit at the 3rd position (starting from the left)...
Since decimal numbers also have a sign, vertical multiplication can't be used if either number is negative. Rather, integer multiplication needs to be used. Integer multiplication makes use of whole number vertical multiplication but also accounts for the sign.
The way to perform this algorithm via code is as follows...
@log_decorator
def __mul__(lhs: DecimalNumber, rhs: DecimalNumber) -> DecimalNumber:
log(f'Multiplying {lhs} and {rhs}...')
log_indent()
adjust_len_self = len(lhs.fractional.digits)
adjust_len_other = len(rhs.fractional.digits)
log(f'Generating mock integer number for {lhs}...')
lhs_extra_0s = adjust_len_self - len(lhs.fractional.digits)
lhs_combined_digits = lhs.fractional.digits + lhs.whole.digits
lhs_combined_digits[0:0] = [Digit(0)] * lhs_extra_0s
mock_self = IntegerNumber(lhs.sign, WholeNumber(lhs_combined_digits))
log(f'{mock_self}')
log(f'Generating mock integer number for {rhs}...')
rhs_extra_0s = adjust_len_other - len(rhs.fractional.digits)
rhs_combined_digits = rhs.fractional.digits + rhs.whole.digits
rhs_combined_digits[0:0] = [Digit(0)] * rhs_extra_0s
mock_other = IntegerNumber(rhs.sign, WholeNumber(rhs_combined_digits))
log(f'{mock_other}')
log(f'Performing {mock_self} * {mock_other}...')
mock_ret = mock_self * mock_other
log(f'{mock_ret}')
log(f'Unmocking {mock_ret} back to decimal...')
unadjust_len = adjust_len_self + adjust_len_other
ret_sign = mock_ret.sign
ret_fractional_digits = [mock_ret.magnitude[i] for i in range(0, unadjust_len)]
ret_whole_digits = [mock_ret.magnitude[i] for i in range(unadjust_len, len(mock_ret.magnitude.digits))]
ret = DecimalNumber(ret_sign, WholeNumber(ret_whole_digits), FractionalNumber(ret_fractional_digits))
log(f'{ret}')
log_unindent()
log(f'{ret}')
return ret↩PREREQUISITES↩
TODO: long division where you shift the divisor and dividend until there is no fractional part, then divide as is... e.g. 0.1 / 0.3 is the result result as 1 / 3 is the same result as 10/30 -- but, you only really need to shift until the divisor is whole, just keep the decimal point in the same place and it'll still work out
TODO: show by converting to fractions
TODO: show using standard long division algorithm (only works if denominator is an integer) -- if not need to scale up e.g. 10/5.2 needs to be scaled to equiv frac of 100/52 and then perform using the standard long division algo
TODO: divide by 10 to move digits down
↩PREREQUISITES↩
Decimal rounding is the process of making a decimal number less exact. Rounding is often used in an attempt to make numbers more convenient at the expense of being less accurate. For example, it's acceptable to say 330 million people live in the USA even though it very likely isn't the exact number of people.
To round a decimal number, ...
For example, to round 123.456 at the tenths position...
locate the tenths position...
is the position immediately following the tenths greater than or equal to 5?
yes, the hundredths position is greater than or equal to 5, so increment at the tenths position...
123.456 + 000.100 = 123.556
set all digits following the tenths to 0...
123.500 (can be shortened to 123.5)
The way to perform this algorithm via code is as follows...
@log_decorator
def round(self: DecimalNumber, position: str) -> DecimalNumber:
log(f'Rounding {self} at {position} position...')
log_indent()
position = position.strip()
if position.endswith('s'):
position = position[:-1]
position_word_to_index = {
'hundred-quintillion': 20,
'ten-quintillion': 19,
'quintillion': 18,
'hundred-quadillion': 17,
'ten-quadrillion': 16,
'quadrillion': 15,
'hundred-trillion': 14,
'ten-trillion': 13,
'trillion': 12,
'hundred-billion': 11,
'ten-billion': 10,
'billion': 9,
'hundred-million': 8,
'ten-million': 7,
'million': 6,
'hundred-thousand': 5,
'ten-thousand': 4,
'thousand': 3,
'hundred': 2,
'ten': 1,
'one': 0,
'tenth': -1,
'hundredth': -2,
'thousandth': -3,
'ten-thousandth': -4,
'hundred-thousandth': -5,
'millionth': -6,
'ten-millionth': -7,
'hundred-millionth': -8,
'billionth': -9,
'ten-billionth': -10,
'hundred-billionth': -11,
'trillionth': -12,
'ten-trillionth': -13,
'hundred-trillionth': -14,
'quadrillionth': -15,
'ten-quadrillionth': -16,
'hundred-quadillionth': -17,
'quintillionth': -18,
'ten-quintillionth': -19,
'hundred-quintillionth': -20,
}
position_idx = position_word_to_index[position]
if position_idx is None:
raise Exception('Position unknown')
next_position_idx = position_idx - 1
log(f'Determining adder based on following position...')
log_indent()
log(f'Checking if digit at following position is >= 5...')
following_digit = WholeNumber.from_digit(self[next_position_idx])
if following_digit >= WholeNumber.from_str("5"):
log(f'True ({following_digit} >= 5), deriving adder based on position...')
if position_idx >= 0:
adder = DecimalNumber(
self.sign,
WholeNumber.from_str('1' + '0' * position_idx),
FractionalNumber.from_str('0')
)
else:
adder = DecimalNumber(
self.sign,
WholeNumber.from_str('0'),
FractionalNumber.from_str('0' * -(position_idx + 1) + '1')
)
else:
log(f'False ({following_digit} < 5), setting adder to 0...')
adder = DecimalNumber.from_str('0')
log_unindent()
log(f'{adder}')
log(f'Adding {adder} to {self}...')
ret = self.copy() + adder
log(f'{ret}')
log(f'Truncating all following positions...')
log_indent()
if position_idx >= 0:
for i in range(0, position_idx):
ret[i] = Digit(0)
log(f'{ret}')
for i in range(0, len(self.fractional.digits)):
ret[-i - 1] = Digit(0)
log(f'{ret}')
else:
for i in range(-position_idx, len(self.fractional.digits)):
ret[-i - 1] = Digit(0)
log(f'{ret}')
log_unindent()
log(f'{ret}')
log_unindent()
log(f'{ret}')
return ret↩PREREQUISITES↩
Recall that a decimal number is another way of representing a mixed number where the denominator is 1 followed by trailing 0s. For example, ...
If a mixed number doesn't have a denominator that qualifies, it may still be convertible to a decimal number so long as an equivalent fraction exists where the denominator does qualify. That is, an equivalent fraction exists where the denominator is 1 followed by trailing 0s. For example, ...
To figure out if a suitable equivalent fraction exists for a conversion, simplify the fraction and get the prime factors of its denominator. As long as those prime factors contain no numbers other than 2 and 5, there is a suitable equivalent fraction available. For example, is suitable because it simplifies to , where the denominator (20) has the prime factors of [2, 2, 5].
If a suitable equivalent fraction does exist, that suitable equivalent fraction can be determined by...
For example, to find the proper equivalent fraction for , begin by taking the denominator and finding the next largest value that's 1 followed by trailing 0s. Since the number of digits in the denominator is 2, the next largest value that's 1 followed by 2 trailing 0s: 100.
Then, divide 100 by 20. This gives back 5, the value you need to multiply 20 by to get it to 100...
is 5
Then, multiply both the numerator and denominator by 5 to get the proper equivalent fraction...
is
@staticmethod
@log_decorator
def to_suitable_fraction(value: FractionNumber) -> FractionNumber:
log(f'Converting {value} to an equivalent fraction with denominator that is power of 10...')
log_indent()
denom = value.denominator
if str(denom)[0] == '1' and (set(str(denom)[1:]) == set() or set(str(denom)[1:]) == set('0')):
log(f'Already power of 10')
else:
log(f'No')
log(f'Simplifying fraction {value}...')
value = value.simplify()
denom = value.denominator
log(f'{value}')
log(f'Calculating unique prime factors of {denom}...')
denom_prime_factors = factor_tree(denom).get_prime_factors()
denom_prime_factors_set = set(denom_prime_factors)
log(f'{denom_prime_factors_set}')
if not({WholeNumber.from_int(2), WholeNumber.from_int(5)} == denom_prime_factors_set
or {WholeNumber.from_int(2)} == denom_prime_factors_set
or {WholeNumber.from_int(5)} == denom_prime_factors_set
or 0 == len(denom_prime_factors_set)):
raise Exception('Simplified denominator contains prime factors other than 2 and 5')
log(f'Calculating value to scale by so {denom} becomes next largest power of 10...')
expected_0s_in_denom = len(str(denom))
expected_denom = WholeNumber.from_str('1' + '0' * expected_0s_in_denom)
scale_by, _ = expected_denom / denom # remainder will be 0
log(f'{scale_by}')
log(f'Scaling {value} by {scale_by}...')
value = value * FractionNumber(
IntegerNumber.from_whole(scale_by),
IntegerNumber.from_whole(scale_by)
)
log(f'{value}')
log_unindent()
log(f'{value}')
return valueTODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
TODO: talk about terminating vs non-terminating decimals -- non-terminating decimals can be explained by the explaination in the place value system of the fractional part
Recall that a decimal number is another way of representing a mixed number where the denominator is 1 followed by trailing 0s. For example, ...
To write a decimal number as a mixed number, ...
For example, to convert the mixed number to a decimal number, begin by counting the number of digits after the decimal point and then adding a denominator starting with a 1 followed by that many 0s...
Then, remove any prefixed 0s on the numerator...
Then, remove the decimal point...
@log_decorator
def as_fraction(self: DecimalNumber) -> FractionNumber:
log(f'Converting {self} to fraction number...')
log_indent()
log(f'Determining denominator based on length of fractional portion ({self.fractional})...')
denom = IntegerNumber.from_str('1' + '0' * len(self.fractional.digits))
log(f'{denom}')
log(f'Converting fractional portion ({self.fractional} to fraction...')
fractional_fraction = FractionNumber(
IntegerNumber.from_str(str(self.fractional)),
denom
)
log(f'{fractional_fraction}')
log(f'Converting whole portion ({self.whole}) to fraction...')
whole_fraction = FractionNumber.from_whole(self.whole)
log(f'{whole_fraction}')
log(f'Adding ({whole_fraction}) to ({fractional_fraction})...')
fraction = whole_fraction + fractional_fraction
log(f'{fraction}')
log(f'Applying sign of ({self.sign}) to {fraction}...')
if self.sign == Sign.NEGATIVE:
fraction = fraction * FractionNumber.from_str("-1/1") # make sign negative
log(f'{fraction}')
log_unindent()
return fractionExamples of mixed number and decimal number equivalents...
↩PREREQUISITES↩
Taking the power of a number is the concept of taking that number and iteratively multiplying it to itself for a certain number of iterations. For example, 2 iteratively multiplied to itself for 4 iterations results in 16...
2*2*2*2=16 <-- 2 to the exponent of 4
[●●] [●●] (2*2=4)
\ /
\ /
[●●●●] [●●] (4*2=8)
\ /
\ /
\ /
\ /
[●●●●●●●●] [●●] (8*2=16)
\ /
\ /
\ /
\ /
\ /
\ /
[●●●●●●●●●●●●●●●●]
Exponentiation is typically represented using either a caret or superscript. The above example could be represented as either...
The output of a exponentiation is called the power. In the example above, 16 is the 4th power of 2.
The inputs into the multiplication operation are ...
⚠️NOTE️️️⚠️
You can think of this as a function that takes in 2 arguments: power(2, 4).
When using words, exponentiation is typically represented using the following syntax:
⚠️NOTE️️️⚠️
Does the terminology here seem confusing?
See [http://mathforum.org/library/drmath/view/64570.html] for more information on why this is.
Special cases to be aware of for exponentiation:
Any base to the power of 0 is 1...
0^0 = 1
1^0 = 1
2^0 = 1
...
⚠️NOTE️️️⚠️
If you know about algebra and multiplication rules, this is because the identify property of multiplication is 1. That is, any number multiplied by 1 is itself. So you can consider...
0 raised to any power other than 1 is 0
0^0 = 1 <-- see prior special case -- any base raised to the 0th power is 1
0^1 = 0
0^2 = 0
0^3 = 0
...
⚠️NOTE️️️⚠️
If you know about algebra and multiplication rules, this is because the identify property of multiplication is 1. That is, any number multiplied by 1 is itself. So you can consider...
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
TODO: algorithm code needs to be moved OUT of whole number and into its own package!!!
There are 2 algorithms used by humans to calculate exponents that are >= 1. The first algorithm is the simplest and most used: multiply base to itself for exponent iterations. For example, to calculate ...
The way to perform this algorithm via code is as follows...
@log_decorator
def iterative_pow(base: WholeNumber, exponent: WholeNumber) -> WholeNumber:
log(f'Computing the power of {base} raised to {exponent} ({base}^{exponent})...')
log_indent()
power = WholeNumber.from_str('1')
while exponent > WholeNumber.from_str('0'):
log(f'Multiplying {power} by {base}...')
power = power * base
exponent -= WholeNumber.from_str('1') # decrement exponent
log_unindent()
log(f'Power: {power}')
return powerThe second algorithm involves keeping a cache to reduce the number multiplications required for exponentiation. That is, it takes advantage of the fact that how you go about multiplying the chain of numbers together doesn't matter -- the product (result) will always be the same.
For example, when calculating , the result will be 32 regardless of the order in which multiplication operations happen...
⚠️NOTE️️️⚠️
If you know algebra, the above diagram is showing the commutative and associative properties of multiplication.
Notice how in the subgroup diagrams above, the numbers are being grouped together and recursively multiplied. If a subgroup has already been calculated once, its result can be cached such that if another subgroup with the same number of multiplications appears that result can be reused. For example, once...
If applied to the example above, the caching mechanism doesn't seem much more efficient...
However, for larger exponents it is much more efficient. For example. calculating using the caching algorithm described above requires only 5 iterations (as opposed to 20 iterations if the first algorithm were used)....
The way to perform this algorithm via code is as follows...
@log_decorator
def __pow__(base: WholeNumber, exponent: WholeNumber, modulo=None):
log(f'Computing the power of {base} raised to {exponent} ({base}^{exponent})...')
log_indent()
cache: OrderedDict[WholeNumber, WholeNumber] = OrderedDict()
cache[WholeNumber.from_str('0')] = WholeNumber.from_str('1')
cache[WholeNumber.from_str('1')] = base
def get_closest_lt_or_eq_cached_exp(e):
key_list = list(cache.keys())
pos = bisect_left(key_list, e)
if pos == 0:
return key_list[0]
if pos == len(cache):
return key_list[-1]
if key_list[pos] == e:
return e
else:
return key_list[pos - 1]
mult_str = '1'
power = WholeNumber.from_str('1')
current_exponent = WholeNumber.from_str('0')
remaining_exponent = exponent
while remaining_exponent > WholeNumber.from_str('0'):
log(f'Step...')
log_indent()
log(f'Remaining Exponent: {remaining_exponent} / Power Cache: {[f"{base}^{k}={v}" for k, v in cache.items()]}')
cached_exponent = get_closest_lt_or_eq_cached_exp(remaining_exponent)
cached_power = cache[cached_exponent]
log(f'Next {cached_exponent} of {remaining_exponent} multiplications can be pulled from cache: {base}^{cached_exponent}={cached_power}')
power *= cached_power
current_exponent += cached_exponent
remaining_exponent -= cached_exponent
mult_str += f'\*{cached_power}'
log(f'{base}^{current_exponent}={mult_str}={power}')
cache[current_exponent] = power
log(f'{base}^{current_exponent}={power} inserted into cache')
log_unindent()
log_unindent()
log(f'Power: {power}')
return powerTODO: negative exponent = repeat division instead of multiplication
TODO: https://math.stackexchange.com/questions/1957055/how-does-an-exponent-work-when-its-less-than-one
TODO: this requires looking a bit into exponent rules, although those shouldn't be expressed in this section as rules will be elaborated on in the algebra section -- for example, 5^(5/2) = 5^2 * 5^(1/2) = 5^2 * sqrt(5)
TODO: make sure to prereq this on some part of the root section -- do your best to not make this is a circular dependency
x^2/1 = root(1/2, x) x^1/1 = root(1/1, x) x^1/2 = root(2/1, x) x^1/3 = root(3/1, x) x^1/4 = root(4/1, x)
↩PREREQUISITES↩
A root operation is the concept of finding the base of a power operation. That is, given the exponent and power (result of exponentiation operation), that exponentiation operation is reversed back to find the original base. For example, an exponent of 2 and a power of 25, the found base would be 5...
Find a base such that when raised to the 2nd power, the result is 25.
?^2=25
0^2=0 -- no, 0 != 25
1^2=1 -- no, 1 != 25
2^2=4 -- no, 2 != 25
3^2=9 -- no, 9 != 25
4^2=16 -- no, 16 != 25
5^2=25 -- yes, 25 = 25
⚠️NOTE️️️⚠️
Confused about roots vs logarithms?
Calculating the root is finding the base: e.g. ?^2=25 Calculating the logarithm is finding the exponent: e.g. 5^?=25
⚠️NOTE️️️⚠️
Why the word root? Think of a tree (nature). The result of exponentiation is the tree with all of its branches, but you're trying to find the root of that tree -- the original number that sprouted to produce that tree with all of its branches.
For example, in 2^4=16, 16 is the tree and 2 is the root. 2 is what sprouted to 16 -- ...
A root operation is typically written as a check mark, where on the...
In the above example, the 2nd root of 25 would be represented as either or .
When using words, a root operation is typically represented using the following syntax:
⚠️NOTE️️️⚠️
Instead of numbers, special words can be used instead:
If you know geometry, the terms square and cube are taken from geometry. Specifically, the area of a ...
square is technically defined ?^2. For example, the area of a 5 by 5 square is 5^2...
cube is technically defined ?^3. For example, the area of a 5 by 5 by 5 square is 5^3...
↩PREREQUISITES↩
A logarithm operation is the concept of finding the exponent of a power operation. That is, given the base and power (result of exponentiation operation), that exponentiation operation is reversed back to find the original exponent. For example, a base of 5 and a power of 125, the found base would be 3...
Find an exponent such that when 5 is raised to some power, the result is 125.
5^?=125
5^0=1 -- no, 1 != 125
5^1=5 -- no, 5 != 125
5^2=25 -- no, 25 != 125
5^3=125 -- yes, 125 = 125
⚠️NOTE️️️⚠️
Confused about roots vs logarithms?
Calculating the root is finding the base: e.g. ?^2=25 Calculating the logarithm is finding the exponent: e.g. 5^?=25
⚠️NOTE️️️⚠️
Why the word logarithm? See [http://mathforum.org/library/drmath/view/55579.html].
A logarithm operation is typically written using the word log immediately followed by the...
In the above example, the log of 125 would be represented as either or .
Special cases to be aware of for logarithms:
TODO: do your best to write some explanations are algorithms for logarithms - http://mathforum.org/library/drmath/view/55563.html
TODO: do your best to write some explanations are algorithms for logarithms - http://mathforum.org/library/drmath/view/55563.html
TODO: do your best to write some explanations are algorithms for logarithms - http://mathforum.org/library/drmath/view/55563.html
TODO: do your best to write some explanations are algorithms for logarithms - http://mathforum.org/library/drmath/view/55563.html
TODO: do your best to write some explanations are algorithms for logarithms - http://mathforum.org/library/drmath/view/55563.html
TODO: do your best to write some explanations are algorithms for logarithms - http://mathforum.org/library/drmath/view/55563.html
TODO: do your best to write some explanations are algorithms for logarithms - http://mathforum.org/library/drmath/view/55563.html
TODO: do your best to write some explanations are algorithms for logarithms - http://mathforum.org/library/drmath/view/55563.html
TODO: do your best to write some explanations are algorithms for logarithms - http://mathforum.org/library/drmath/view/55563.html
TODO: do your best to write some explanations are algorithms for logarithms
TODO: do your best to write some explanations are algorithms for logarithms
TODO: do your best to write some explanations are algorithms for logarithms
TODO: do your best to write some explanations are algorithms for logarithms
TODO: do your best to write some explanations are algorithms for logarithms
TODO: do your best to write some explanations are algorithms for logarithms
TODO: do your best to write some explanations are algorithms for logarithms
TODO: do your best to write some explanations are algorithms for logarithms
TODO: do your best to write some explanations are algorithms for logarithms
↩PREREQUISITES↩
TODO: example is sqrt(2)
↩PREREQUISITES↩
Algebra is the study of mathematical operations and the rules for manipulating those operations.
Common mathematical operations:
These operations can typically be chained together. One or more operations combined together is called an expression. For example, is an expression.
The operations in an expression can make use of either constants or variables. A...
For example, the expression has the constant 3 and the variable x. Note that the variable x is used 2 times in the expression -- when its set to a number, both instances of x in the expression must change to that number. For example, if x were set to 5, the expression would be .
TODO: BEDMAS
To simplify an expression is to perform all the math operations possible on the expression. For example, in , first the multiplication gets performed to make the expression , then the addition gets performed to make the expression .
To evaluate an expression is to (replace) set all of its variables to numbers and perform all the operations. In other words, set all variables to a number and simplify the expression.
In an expression, the word...
⚠️NOTE️️️⚠️
The book states that the term 7 has a coefficient of 7, but this doesn't mesh with the description that the book gives for coefficients -- "The constant that multiplies the variable(s) in a term is called the coefficient." Other sources seem to corroborate that a constant by itself doesn't equality as a coefficient: https://www.youtube.com/watch?v=uiIg6ADVz8c.
2 terms are considered like terms if they either...
Like terms can be combined together by adding the coefficients. For example, 4x+2x can be simplified to 6x. The reason for this is that multiplication is just iterative addition -- it becomes apparent once 4x and 2x get broken down as addition in the expression ...
4x 2x
┌─────────────┐ ┌─────┐
x + x + x + x + x + x
└─────────────────────┘
7x
⚠️NOTE️️️⚠️
If multiple additions are being chained together, often times its helpful to re-order it so that like terms are together -- it makes it easier to combine like terms. You can do this because of the commutative property of addition. For example..
5x^2 + 3y + 4x^2 + 2y can be re-order as 5x^2 + 4x^2 + 3y + 2y
When 2 expressions evaluate to the same result, they can be written as an equation. An equation is denoted by a =, where the left-side is one expression and the right-side is another. For example, .
To solve an equation means to determine the values of the variables in the equation such that both sides evaluate to the same number. This is done by applying the various rules of the operations used in the expressions of the equation. For example, solving ...
The set of variable to number mappings for an equation is called a solution -- is the solution of the equation.
TODO: write section on converting words to algebra / algebra to words (see "Translate Words to Algebraic Expressions" in chapter 2.2) -- write a solver for this and make sure it handles complex expressions (e.g. nine times five less than twice x = 2x-(9*5)). If you see a comma, treat it like you're putting parenthesis around everything before and then applying the stuff after -- e.g. sum of 4 and 1, increased by 8 = (4+1) + 8.
Algebraic terminology:
Algebraic notation:
-- a equals b
When both sides represent the same value, it's said that they're equal.
- a NOT equals b
When both sides represent different value, it's said that they're not equal.
-- greater than
When the value of left-side is more than the right-side, the left is said to be greater than the right.
⚠️NOTE️️️⚠️
This is the same as . Think of the symbol as a mouth. The mouth is trying to eat the larger value -- it's open in that direction.
-- less than
When the value of left-side is less than the right-side, the left is said to be greater than the right.
⚠️NOTE️️️⚠️
This is the same as . Think of the symbol as a mouth. The mouth is trying to eat the larger value -- it's open in that direction.
-- greater than or equal
When the value of left-side is more OR equal to the right-side, the left is said to be greater than the right.
When the value of left-side is less than OR equal to the right-side, the left is said to be greater than the right.
KEEP WORKING ON THESE: ADD FRACTION ADDING AND MULTIPLICATION RULES (recipriocals, cross multiply, etc..) ADD REMAINING ALGEBRA RULES https://en.wikiversity.org/wiki/Algebraic_Properties_of_Equality https://en.wikiversity.org/wiki/Basic_Laws_of_Algebra http://www.themathpage.com/aPreCalc/algebraPre.htm (specifically 1, 6, and 7?) ADD TRIVIAL AND NON-TRIVIAL EXAMPLES
TODO: write section about converting expressions to phrases and vice versa
The order of operations are as follows:
These rules are often abbreviated as either...
Note that these 2 are essentially the same. Division and multiplication are swapped, but since division and multiplication are evaluated left-to-right in the same step, it makes no difference.
TODO: talk about inverse of an operation, properties such as commutatitive, etc.. and make sure to properly bookmark them so they can be referenced from the neighbouring equality rules section below. move the stuff below into its relevant subsections
Commutative Property
Associative Property
Distributive Property
Identity Property
Additive Inverse Property
Multiplicative Inverse / Multiplicative Reciprocal Property
Subtraction Property
inverse of addition is subtraction
inverse of subtraction is addition
inverse of division
inverse of multiplication
TODO: fraction bars as grouping -- treat the numerator as if it was in parenthesis and the denominator as if it were in parenthesis
TODO: talk about how you can subtract/add/multiply/divide anything so long as you do it to both sides... e.g. x=5 add y to both sides to get x+y=5+y, x+y=5+y subtract y from both sides to get
using a balancing scale might be a good way to represent this -- if it's already balanced, adding 5 apples to one side means you have to add 5 apples to the other side to keep it balanced
starts at section 2.3
see subtraction property of equality
see addition property of equality
see division property of equality
see multiplciation property of equality
ALSO, section 2.3 talks about converting phrases to equations and viceversa -- implement this (see "Translate Word Phrases to Algebraic Equations" section)... words that map to equality...
!{bm} is equal to -- e.g. x is equal to 1!{bm} equals -- e.g. x equals 1!{bm} is the same as -- e.g. x is the same as 1!{bm} is -- e.g. x is 1!{bm} gives -- e.g. ???!{bm} was -- e.g. x was 1!{bm} will be -- e.g. x will be 1some of the above are overkill and need to be pruned
TODO: discuss as if it were a scale
TODO: discuss as on a number line -- if a is greater than b, a is to the right of b
TODO: write this up from section 3.1 of openstax prealg book
Absolute value has the same precedence as parenthesis when it comes to order of operations --
TRY IT
1.1)
1.2)
1.3) 176
1.4) 237
1.5) 63,407,218
1.6) 27,493,615
1.7) 9,258,137,904,061
9 -> nine trillion
258 -> two hundred fifty eight billion
137 -> one hundred thirty seven million
904 -> nine hundred and four thousand
061 -> sixty one
1.8) 17,864,325,619,004
17 -> seventeen trillion
864 -> eight hundred sixty four billion
325 -> three hundred twenty five million
619 -> six hundred nineteen thousand
004 -> and four
1.9) 316,128,839
316 -> three hundred sixteen million
128 -> one hundred twenty eight thousand
839 -> eight hundred thirty nine
1.10) 31,536,000
31 -> thirty one
536 -> five hundred thirty six thousand
000 ->
1.11) fifty-three million, eight hundred nine thousand, fifty-one -> 536,809,051
1.12) two billion, twenty-two million, seven hundred fourteen thousand, four hundred sixty-six -> 2,022,714,466
1.13) 34 million -> 34,000,000
1.14) 204 million -> 204,000,000
1.15) 157 rounded to nearest ten: 160
1.16) 884 rounded to nearest ten: 880
1.17) 17,852 rounded to nearest hundred: 17,900
1.18) 4,951 rounded to nearest hundred: 5,000
1.19) 63,921 rounded to nearest thousand: 64,000
1.20) 156,437 rounded to nearest thousand: 156,000
EXERCISE
1.1.1)
1.1.2)
1.1.3)
1.1.4)
1.1.5) 561
1.1.6) 384
1.1.7) 461
1.1.8) 620
1.1.9) 579,601
1.1.10) 398,127
1.1.11) 56,804,379
1.1.12) 78,320,465
1.1.13) 1,078 -> one thousand seventy eight
1.1.14) 5,902 -> five thousand nine hundred two
1.1.15) 364,510 -> three hundred sixty four thousand five hundred ten
1.1.16) 146,023 -> one hundred forty six thousand twenty three
1.1.17) 5,846,103 -> five million eight hundred forty six thousand one hundred three
1.1.18) 1,458,398 -> one million four hundred fifty eight thousand three hundred ninety eight
1.1.19) 37,889,005 -> thirty seven million, eight hundred eighty nine thousand five
1.1.20) 62,008,465 -> sixty two million eight thousand four hundred sixty five
1.1.21) 14,410 -> fourteen thousand four hundred ten
1.1.22) 12,276 -> twelve thousand two hundred seventy six
1.1.23) 613,000 -> six hundred thirteen thousand
1.1.24) 525,600 -> five hundred twenty five thousand six hundred
1.1.25) 2,617,176 -> two million six hundred seventeen thousand one hundred seventy six
1.1.26) 2,718,782 -> two million seven hundred eighteen thousand seven hundred eighty two
1.1.27) 23,867,000 -> twenty three million eight hundred sixty seven thousand
1.1.28) 20,665,415 -> twenty million six hundred sixty five thousand four hundred fifeteen
1.1.29) 1,377,583,156 -> one billion three hundred seventy seven million five hundred eighty three thousand one hundred fifty six
1.1.30) 1,267,401,849 -> one billion two hundred sixty seven million four hundred one thousand eight hundred forty nine
1.1.31) four hundred twelve -> 412
1.1.32) two hundred fifty-three -> 253
1.1.33) thirty-five thousand, nine hundred seventy-five -> 35,975
1.1.34) sixty-one thousand, four hundred fifteen -> 61,415
1.1.35) eleven million, forty-four thousand, one hundred sixty-seven -> 11,044,167
1.1.36) eighteen million, one hundred two thousand, seven hundred eighty-three -> 18,102,783
1.1.37) three billion, two hundred twenty-six million, five hundred twelve thousand, seventeen -> 3,226,512,17
1.1.38) eleven billion, four hundred seventy-one million, thirty-six thousand, one hundred six -> 11,471,036,106
1.1.39) seven billion, one hundred seventy-three million -> 7,173,000,000
1.1.40) four billion, five hundred sixty-eight million years -> 4,568,000,000
1.1.41) thirty-nine trillion -> 39,000,000,000
1.1.42) three trillion, five hundred billion -> 3,500,000,000
1.1.43) round to nearest ten
1.1.44) round to nearest ten
1.1.45) round to nearest hundred
1.1.46) round to nearest hundred
1.1.47) round to nearest ten
1.1.48) round to nearest thousand
1.1.49) round to nearest hundred
1.1.50) round to nearest thousand
1.1.51) 24,493 -> twenty four thousand four hundred ninety three
1.1.52) 18,549 -> eighteen thousand five hundred forty nine
1.1.53) round 24,493 to the nearest...
1.1.54) round 18,549 to the nearest...
1.1.55) round 1,355,692,544 to the nearest...
1.1.56) round 149,597,888 to the nearest...
1.1.57)
The difference between counting numbers and whole numbers is that counting numbers start at 1 while whole numbers start at 0. The reason is that counting numbers are used when you're counting something. You usually need to have 1 of something to start counting. For example, I can't count the number of apples if there are no apples. I need at least 1 apple to be able to count.
1.1.58)
It's easier to say numbers that are rounded. For example...
58,123 -> fifty eight thousand one hundred twenty three 58,000 -> fifty eight thousand
Less words to speak while conveying approximately the same quantity.
TRY IT
1.21) write out...
1.22) write out...
1.23) model 3 + 6...
□□□ □□□□□□
3 6
1.24) model 5 + 1...
□□□□□ □
5 1
1.25) model 5 + 7...
□□□□□ □□□□□□□
5 7
1.26) model 6 + 8...
□□□□□□ □□□□□□□□
6 8
1.27) model 15 + 27...
□□□□□□□□□□ □□□□□□□□□□
□□□□□ □□□□□□□□□□
□□□□□□□
15 27
1.28) model 16 + 29...
□□□□□□□□□□ □□□□□□□□□□
□□□□□□ □□□□□□□□□□
□□□□□□□□□
16 29
1.29)
a) 0+19=19 b) 39+0=39
1.30)
a) 0+24=24 b) 57+0=57
1.31) 9+7=16 and 7+9=16
1.32) 8+6=14 and 6+8=14
1.33) 32+54
32
54 +
--
86
1.34) 25+74
25
74 +
--
89
1.35) 35+98
1 <-- carry over
35
98 +
--
133
1.37) 456+376
11 <-- carry over
456
376 +
---
1032
1.38) 269+578
11 <-- carry over
269
578 +
---
847
1.39) 4597+685
111 <-- carry over
4597
685 +
----
5282
1.40) 5837+695
111 <-- carry over
5837
695 +
----
5282
1.41) 46195+397+6281
1 21 <-- carry over
46195
397
6281 +
-----
52873
1.42) 53762+196+7458
1121 <-- carry over
53762
196
7458 +
-----
61416
1.43) 17+26=43
1.44) 28+14=42
1.45) 29+76=105
1.46) 37+69=106
1.47) 18+15+26+49+32=140
1.48) 230+165+325=720
1.49) 3+3+3+2+2+4+4+9=32
1.50) 4+4+2+2+4+6+12+2=36
EXERCISE
1.2.59) five plus two
1.2.60) six plus three
1.2.61) thirteen plus eighteen
1.2.62) fifteen plus sixteen
1.2.63) two hundred fourteen plus six hundred forty two
1.2.64) four hundred thirty eight plus one hundred thirteen
1.2.65) model 2 + 4...
□□ □□□□
2 4
1.2.66) model 5 + 3...
□□□□□ □□□
5 3
1.2.67) model 8 + 4...
□□□□□□□□ □□□
8 4
1.2.68) model 5 + 9...
□□□□□ □□□□□□□□□
5 9
1.2.69) model 14 + 75...
□□□□□□□□□□ □□□□□□□□□□
□□□□ □□□□□□□□□□
14 □□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□
75
1.2.70) model 15 + 63...
□□□□□□□□□□ □□□□□□□□□□
□□□□□ □□□□□□□□□□
15 □□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□
63
1.2.71) model 16 + 25...
□□□□□□□□□□ □□□□□□□□□□
□□□□□□ □□□□□□□□□□
16 □□□□□
25
1.2.72) model 14 + 27...
□□□□□□□□□□ □□□□□□□□□□
□□□□ □□□□□□□□□□
14 □□□□□□□
27
1.2.73) Missing blocks filled in...
| + | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 2 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 3 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 4 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 5 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 6 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 7 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 8 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 15 | 16 |
| 9 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
1.2.74) Missing blocks filled in...
| + | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 2 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 3 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 4 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 5 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 6 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 7 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 8 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 15 | 16 |
| 9 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
1.2.75) Missing blocks filled in...
| + | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|
| 6 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 7 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 8 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 9 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
1.2.76) Missing blocks filled in...
| + | 6 | 7 | 8 | 9 |
|---|---|---|---|---|
| 3 | 6 | 7 | 8 | 9 |
| 4 | 7 | 8 | 9 | 10 |
| 5 | 8 | 9 | 10 | 11 |
| 6 | 9 | 10 | 11 | 12 |
| 7 | 10 | 11 | 12 | 13 |
| 8 | 11 | 12 | 13 | 14 |
| 9 | 12 | 13 | 14 | 15 |
1.2.77) Missing blocks filled in...
| + | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|
| 5 | 10 | 11 | 12 | 13 | 14 |
| 6 | 11 | 12 | 13 | 14 | 15 |
| 7 | 12 | 13 | 14 | 15 | 16 |
| 8 | 13 | 14 | 15 | 15 | 16 |
| 9 | 14 | 15 | 16 | 17 | 18 |
1.2.78) Missing blocks filled in...
| + | 6 | 7 | 8 | 9 |
|---|---|---|---|---|
| 6 | 12 | 13 | 14 | 15 |
| 7 | 13 | 14 | 15 | 16 |
| 8 | 14 | 15 | 15 | 16 |
| 9 | 15 | 16 | 17 | 18 |
1.2.79)
a) 0+13=13 b) 13+0=0
1.2.80)
a) 0+5280 = 0 b) 5280+0 = 0
1.2.81)
a) 8+3=11 b) 3+8=11
1.2.82)
a) 7+5=12 b) 5+7=12
1.2.83)
<-- carry over
45
33 +
--
78
1.2.84)
<-- carry over
37
22 +
--
59
1.2.85)
<-- carry over
71
28 +
--
99
1.2.86)
<-- carry over
43
53 +
--
96
1.2.87)
1 <-- carry over
26
59 +
--
85
1.2.88)
1 <-- carry over
38
17 +
--
55
1.2.89)
1 <-- carry over
64
78 +
--
143
1.2.90)
1 <-- carry over
92
39 +
--
131
1.2.91)
1 <-- carry over
168
325 +
---
493
1.2.92)
1 <-- carry over
247
149 +
---
396
1.2.93)
11 <-- carry over
584
277 +
---
861
1.2.94)
11 <-- carry over
175
648 +
---
823
1.2.95)
11 <-- carry over
832
199 +
---
1031
1.2.96)
11 <-- carry over
775
369 +
---
1144
1.2.97)
11 <-- carry over
6358
492 +
----
6850
1.2.98)
11 <-- carry over
9184
578 +
----
9762
1.2.99)
111 <-- carry over
3740
18593 +
-----
22333
1.2.100)
111 <-- carry over
6118
15990 +
-----
22108
1.2.101)
11 1 <-- carry over
485012
619848 +
------
1104860
1.2.102)
11111 <-- carry over
368911
857289 +
------
1226200
1.2.103)
211 <-- carry over
24731
592
3868 +
-----
29191
1.2.104)
1211 <-- carry over
28925
817
4593 +
-----
34335
1.2.105)
2111 <-- carry over
8015
76946
16570 +
-----
101531
1.2.106)
1111 <-- carry over
6291
54107
28635 +
-----
89033
1.2.107) 13+18=31
1.2.108) 12+19=31
1.2.109) 90+65=155
1.2.110) 70+38=108
1.2.111) 33+49=82
1.2.112) 68+25=93
1.2.113) 250+599=849
1.2.114) 115+286=401
1.2.115) 628+77=705
1.2.116) 593+79=672
1.2.117) 1482+915=2397
1.2.118) 2719+682=3401
1.2.119) 1100+250+525=1875
1.2.120) 299+35+68=402
1.2.121) 14+19+12+25+68=137
1.2.122) 19+12+23+29+44=115
1.2.123) 238+120+156+196+100+132+225=167
1.2.124)
33 <-- carry over
175
192
148
169
205
181
225 +
---
1295
1.2.125)
1111 <-- carry over
82572
79316
75298 +
-----
237186
1.2.126)
11221 <-- carry over
292540
505875
423699 +
------
1222114
1.2.127) 14+12+18=44
1.2.128) 12+13+5=30
1.2.129) 7+7+21+21=14+42=56
1.2.130) 14+14+19+19=28+38=66
1.2.131) 18+18+19+16=36+35=71
1.2.132) 17+17+24+29=34+24+29=58+29=87
1.2.133) 4+5+3+19+7+24=62
1.2.134) 25+11+7+14+10=67
1.2.135) 320+170+150=640
1.1.136) 420+230+580=1230
1.1.137) 82+91+75+88+70=406 -- yes, it passed
1.1.138) 210+145+183+230+159+164=355+183+230+159+164=585+183+159+164=768+159+164=927+164=1091 -- yes, its below
1.1.139) Very confident
1.1.140) Will codify model as software and embed into notes.
TRY IT
1.51)
a) twelve minus four b) twenty nine minus eleven
1.52)
a) eleven minus two b) twenty nine minus twelve
1.53) model 9 - 6
□□□□□□□□□ 9
┌────────┐
□□□ │ □□□□□□ │ remove 6 from 9
3 └────────┘
6
1.54) model 6 - 1
□□□□□□ 6
┌───┐
□□□□□ │ □ │ remove 1 from 6
5 └───┘
1
1.55) model 12 - 7
□□□□□□□□□□□□ 12
┌─────────┐
□□□□□ │ □□□□□□□ │ remove 7 from 12
5 └─────────┘
7
1.56) model 14 - 8
□□□□□□□□□□□□□□ 14
┌──────────┐
□□□□□□ │ □□□□□□□□ │ remove 8 from 14
6 └──────────┘
8
1.57) model 42 - 27
□□□□□□□□□□ 42
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□
□□□□□□□□□□ 15
□□□□□ ┌───────┐
┌────┘ □□□□□ │
│ □□□□□□□□□□ │ 27
│ □□□□□□□□□□ │
│ □□ ┌───────┘
└────┘
1.58) model 45 - 29
□□□□□□□□□□ 45
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□
□□□□□□□□□□ 16
□□□□□□ ┌──────┐
┌─────┘ □□□□ │
│ □□□□□□□□□□ │ 29
│ □□□□□□□□□□ │
│ □□□□□ ┌────┘
└───────┘
1.59) 7-0=7, 7+0=7
1.60) 6-2=4, 4+2=6
1.61) subtract and check: 86-54
54
32 +
--
86
1.62) subtract and check: 99-74
74
25+
--
99
1.63) subtract and check: 93-58
1 <-- carry over
58
35 +
--
93
1.64) subtract and check: 81-39
1 <-- carry over
39
42 +
--
81
1.65) subtract and check: 439-52
1 <-- carry over
52
387 +
---
439
1.66) subtract and check: 318 - 75
1 <-- carry over
243
75 +
---
318
1.67) subtract and check: 832 - 376
11 <-- carry over
376
456 +
---
832
1.68) subtract and check: 847 - 578
11 <-- carry over
578
269 +
---
847
1.69) subtract and check: 4585 - 697
111 <-- carry over
697
3888 +
----
4585
1.70) subtract and check: 5637 - 899
11 <-- carry over
1899
4738 +
----
5637
1.71)
1.72)
1.73) 77-58=19
1.74) 90-73=17
1.75) 648-499=149
1.76) 285-149=136
EXERCISE
1.3.141) fifteen minus nine
1.3.142) difference of eighteen and sixteen
1.3.143) subtract thirty five from forty two
1.3.144) sixty four less than forty three
1.3.145) six hundred seventy five minus three hundred fifty
1.3.146) difference between seven hundred ninety and five hundred twenty five
1.3.147) model 5 - 2
□□□□□ 5
┌────┐
□□□ │ □□ │ 5-2
└────┘
1.3.148) model 8 - 4
□□□□□□□□ 8
┌──────┐
□□□□ │ □□□□ │ 8-4
└──────┘
1.3.149) model 6 - 3
□□□□□□ 6
┌─────┐
□□□ │ □□□ │ 6-3
└─────┘
1.3.150) model 7 - 5
□□□□□□□ 7
┌───────┐
□□ │ □□□□□ │ 7-5
└───────┘
1.3.151) model 18 - 5
□□□□□□□□□□
□□□□□□□□ 18
□□□□□□□□□□
┌───────┐
□□□ │ □□□□□ │ 18-5
└───────┘
1.3.152) model 19 - 8
□□□□□□□□□□
□□□□□□□□□ 19
□□□□□□□□□□
┌──────────┐
□ │ □□□□□□□□ │ 19-8
└──────────┘
1.3.153) model 17 - 8
□□□□□□□□□□
□□□□□□□ 17
□□□□□□□□□ ┌───┐
┌────────┘ □ │
│ □□□□□□□ ┌──┘ 17-8
└─────────┘
1.3.154) model 17 - 9
□□□□□□□□□□
□□□□□□□ 17
□□□□□□□□ ┌────┐
┌───────┘ □□ │
│ □□□□□□□ ┌──┘ 17-9
└─────────┘
1.3.155) model 35 - 13
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□ 35
□□□□□□□□□□
□□□□□□□□□□
□□ ┌──────────┐
┌─┘ □□□□□□□□ │
│ □□□□□ ┌────┘ 35-13
└───────┘
1.3.156) model 32 - 11
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□ 32
□□□□□□□□□□
□□□□□□□□□□
□ ┌───────────┐
┌─┘ □□□□□□□□□ │
│ □ ┌─────────┘ 32-11
└───┘
1.3.157) model 61 - 47
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□ 61
□□□□□□□□□□
□□□□ ┌────────┐
┌────┘ □□□□□□ │
│ □□□□□□□□□□ ┌┘
│ □□□□□□□□□□ │
│ □□□□□□□□□□ │
│ □□□□□□□□□□ │
│ □ ┌────────┘ 64-47
└───┘
1.3.158) model 55 - 36
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□□□□□□
□□□□□ 55
□□□□□□□□□□
□□□□□□□□□ ┌───┐
┌─────────┘ □ │
│ □□□□□□□□□□ ┌┘
│ □□□□□□□□□□ │
│ □□□□□□□□□□ │
│ □□□□□ ┌────┘ 55 - 36
└───────┘
1.3.159) 9-4=5
1.3.160) 9-3=6
1.3.161) 8-0=8
1.3.162) 2-0=2
1.3.163)
1.3.164)
1.3.165)
1.3.166)
1.3.167)
1.3.168)
1.3.169)
1.3.170)
1.3.171)
1.3.172)
1.3.173)
1.3.174)
1.3.175)
1.3.176)
1.3.177)
1.3.178)
1.3.179)
1.3.180)
1.3.181)
1.3.182)
1.3.183) 10-3 = 7
1.3.184) 12 - 8 = 4
1.3.185) 15 - 4 = 11
1.3.186) 18 - 7 = 11
1.3.187) 9 - 6 = 4
1.3.188) 9 - 8 = 1
1.3.189) 75 - 28 = 47
1.3.190) 81 - 59 = 22
1.3.191) 45-20=25
1.3.192) 37-24=13
1.3.193) 92-67=25
1.3.194) 75-49=26
1.3.195) 16-12=4
1.3.196) 19-15=4
1.3.197) 61-38=23
1.3.198) 62-47=15
1.3.199) 76-47=29
1.3.200) 91-53=38
1.3.201) 256-184=72
1.3.202) 305-262=43
1.3.203)
1 <-- carry over
719
341+
---
1060
1.3.204)
1 <-- carry over
647
528+
---
1175
1.3.205)
1.3.206)
1.3.207) 35+75=110
1.3.208) 33+60=93
1.3.209) 41-13=28
1.3.210) 36-28=8
1.3.211) 100-76=24
1.3.212) 1000-945=55
1.3.213) 80-63=17
1.3.214) 97-73=24
1.3.215) 35-22=13
1.3.216) 82-46=36
1.3.217) 650-399=251
1.3.218) 1600-755=845
1.3.219) 840-685=155
1.3.220) 1125-892=233
1.3.221) 115+230=345 502-345=157
1.3.222) 75+50+70+80=275 350-275=75
1.3.223) one is the opposite of the other
1.3.224) verification
TRY IT
1.77)
1.78)
1.79)
□□□□
□□□□
□□□□
□□□□
□□□□
□□□□
1.80)
□□□□□
□□□□□
□□□□□
□□□□□
□□□□□
□□□□□
□□□□□
1.81)
1.82)
1.83)
1.84)
1.85)
1.86)
1.87)
3 <-- carry over
64
8 *
--
512
1.88)
4 <-- carry over
57
6 *
--
342
1.89)
23 <-- carry over
347
5 *
---
1705
1.90)
41 <-- carry over
462
7
---
3234
1.91)
1.92)
1.93)
a)
b)
1.94)
a)
b)
1.95)
1.96)
1.97)
1.98)
1.99)
1.100)
1.101)
1.102)
1.103)
1.104) 8 * 10 = 80
1.105) 2*14=28
1.106) 2*18=36
1.107) 16*20=320
1.108)
1.109) 8 * 50 = 40
1.110) 45 * 20 = 900
EXERCISE
1.4.225) product of four and seven
1.4.226) eight times six
1.4.227) product of five and twelve
1.4.228) three times nine
1.4.229) ten times twenty five
1.4.230) twenty times fifteen
1.4.231) forty two times thirty three
1.4.232) thirty nine times sixty four
1.2.233)
□□□
□□□
□□□
□□□
□□□
□□□
1.2.234)
□□□□
□□□□
□□□□
□□□□
□□□□
1.2.235)
□□□□□
□□□□□
□□□□□
□□□□□
□□□□□
□□□□□
□□□□□
□□□□□
□□□□□
1.2.237)
| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 2 | 0 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 |
| 3 | 0 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 |
| 4 | 0 | 4 | 8 | 12 | 15 | 20 | 24 | 28 | 32 | 36 |
| 5 | 0 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 |
| 6 | 0 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 |
| 7 | 0 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 |
| 8 | 0 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 |
| 9 | 0 | 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 |
1.2.238)
| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 2 | 0 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 |
| 3 | 0 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 |
| 4 | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 |
| 5 | 0 | 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 |
| 6 | 0 | 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 |
| 7 | 0 | 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 |
| 8 | 0 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 |
| 9 | 0 | 9 | 18 | 27 | 36 | 45 | 56 | 63 | 72 | 81 |
1.2.239)
| x | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|
| 4 | 12 | 16 | 20 | 24 | 28 | 32 | 36 |
| 5 | 15 | 20 | 25 | 30 | 35 | 40 | 45 |
| 6 | 18 | 24 | 30 | 36 | 42 | 48 | 54 |
| 7 | 21 | 28 | 35 | 42 | 49 | 56 | 63 |
| 8 | 24 | 32 | 40 | 48 | 56 | 64 | 72 |
| 9 | 27 | 36 | 45 | 54 | 63 | 72 | 81 |
1.2.240)
| x | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|
| 3 | 12 | 15 | 18 | 21 | 24 | 27 |
| 4 | 16 | 20 | 24 | 28 | 32 | 36 |
| 5 | 20 | 25 | 30 | 35 | 40 | 45 |
| 6 | 24 | 30 | 36 | 42 | 48 | 54 |
| 7 | 28 | 35 | 42 | 49 | 56 | 63 |
| 8 | 32 | 40 | 48 | 56 | 64 | 72 |
| 9 | 36 | 45 | 54 | 63 | 72 | 81 |
1.2.241)
| x | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|
| 6 | 24 | 30 | 36 | 42 | 48 | 54 |
| 7 | 28 | 35 | 42 | 49 | 56 | 63 |
| 8 | 32 | 40 | 48 | 56 | 64 | 72 |
| 9 | 36 | 45 | 54 | 63 | 72 | 91 |
1.2.242)
| x | 6 | 7 | 8 | 9 |
|---|---|---|---|---|
| 3 | 18 | 21 | 24 | 27 |
| 4 | 24 | 28 | 32 | 36 |
| 5 | 30 | 35 | 40 | 45 |
| 6 | 36 | 42 | 48 | 54 |
| 7 | 42 | 49 | 56 | 63 |
| 8 | 68 | 56 | 64 | 72 |
| 9 | 54 | 63 | 72 | 81 |
1.2.243)
| x | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|
| 5 | 25 | 30 | 35 | 40 | 45 |
| 6 | 30 | 36 | 42 | 48 | 54 |
| 7 | 35 | 42 | 49 | 56 | 63 |
| 8 | 40 | 48 | 56 | 64 | 72 |
| 9 | 45 | 54 | 63 | 72 | 91 |
1.2.244)
| x | 6 | 7 | 8 | 9 |
|---|---|---|---|---|
| 6 | 36 | 42 | 48 | 54 |
| 7 | 42 | 49 | 56 | 63 |
| 8 | 48 | 56 | 64 | 72 |
| 9 | 54 | 63 | 72 | 91 |
1.2.245) 0 * 15 = 15
1.2.246) 0 * 41 = 0
1.2.247) 99 * 0 = 0
1.2.248) 77 * 0 = 0
1.2.249) 1 * 43 = 43
1.2.250) 1 * 34 = 34
1.2.251) 28 * 1 = 1
1.2.252) 65 * 1 = 1
1.2.253) 1 * 240055 = 240055
1.2.254) 1 * 189206 = 189206
1.2.255)
1.2.256)
1.2.257)
1.2.258)
1.2.259)
1.2.260)
1.2.261)
1.2.262)
1.2.263)
1.2.264)
1.2.265)
1.2.266)
1.2.267)
1.2.268)
1.2.269) 23 * 10 = 230
1.2.270) 19 * 10 = 190
1.2.271) 100 * 36 = 3600
1.2.272) 100 * 25 = 2500
1.2.273) 1000 * 88 = 88000
1.2.274) 1000 * 46 = 46000
1.2.275) 50 * 1000000 = 50000000
1.2.276) 30 * 1000000 = 30000000
1.2.277)
1.2.278)
1.2.279)
1.2.280)
1.2.281)
1.2.282)
1.2.283)
1.2.284)
1.2.285)
1.2.286)
1.2.287)
1.2.288)
1.2.289) 18 * 33 = 540 + 54 = 594
1.2.290) 15 * 22 = 300 + 30 = 330
1.2.291) 51 * 67 = 3060 + 357 = 3417
1.2.292) 48 * 71 = 3360 + 48 = 3408
1.2.293) 2 * 249 = 498
1.2.294) 2 * 589 = 1178
1.2.295) 10 * 375 = 3750
1.2.296) 10 * 255 = 2550
1.2.297)
1.2.298)
1.2.299)
1.2.300)
1.2.301)
1.2.302)
1.2.303)
1.2.304)
1.2.305) 947 * 0 = 0
1.2.306) 947 + 0 = 947
1.2.307) 15382 + 1 = 15383
1.2.308) 15382 * 1 = 15383
1.2.309) 50 - 18 = 32
1.2.310) 90 - 66 = 24
1.2.311) 2 * 35 = 70
1.2.312) 2 * 140 = 280
1.2.313) 2 * 980 = 1800 + 160 + 0 = 1960
1.2.314) 325 + 65 = 390
1.2.315) 875 * 12 = 8750 + 1750 = 10500
1.2.316) 905 * 15 = 9050 + 4525 = 13575
1.2.317) 89 - 74 = 15
1.2.318) 99 - 45 = 54
1.2.319) 3075 + 950 = 4025
1.2.320) 6308 + 724 = 7032
1.2.321) 814 - 366 = 448
1.2.322) 925 - 388 = 537
1.2.323) 9 * 6 = 54
1.2.324) 6 * 4 = 24
1.2.325) 7 * 44 = 308
1.2.326) 24 * 8 = 192
1.2.327) 15 * 12 = 150 + 30 = 180
1.2.328) 28 * 26 = 560 + 168 = 728
1.2.329) 2 * 10 = 20
1.2.330) 12 * 2 = 24
1.2.331) 50 * 2 = 100
1.2.332) 30 * 2 = 60
1.2.333) 13 * 9 = 117
1.2.334) 18 * 3 = 54
1.2.335) 42 * 34 = 1428
1.2.336) 23 * 28 = 644
1.2.337) 94 * 50 = 4700
1.2.338) 360 * 160 = 36660
1.2.339) 300 * 12 = 3600
1.2.340) 200 * 24 = 4800
1.2.341) yes
1.2.342) verification
TRY IT
1.111)
1.112)
1.113)
□□□□□□ □□□□□□ □□□□□□ □□□□□□
6 6 6 6
24 total
1.114)
□□□□□□□ □□□□□□□ □□□□□□□ □□□□□□□ □□□□□□□ □□□□□□□
7 7 7 7 7 7
42 total
1.115)
1.116)
1.117)
1.118)
1.119)
1.120)
1.121)
1.122)
1.123)
1.124)
1.125)
1.126)
1.127)
1.128)
1.129)
1.130)
1.31)
1.132)
1.133) 91 / 13 = 7
1.134) 52 / 13 = 4
1.135) 135 / 9 = 15
1.136) 36 / 4 = 9
EXERCISE
1.5.343) fifty four divided by nine, quotient of fifty four and nine, nine divided into fifty four
1.5.344) fifty six divided by seven, quotient of fifty six and seven, seven divided into fifty six
1.5.345) thirty two divided by eight, quotient of thirty two and eight, eight divided into thirty two
1.5.346) forty two divided by six, quotient of forty two and six, six divided into forty two
1.5.347) forty eight divided by six, quotient of forty eight and six, six divided into forty eight
1.5.348) sixty three divided by nine, quotient of sixty three and nine, nine divided into sixty three
1.5.349) sixty three divided by seven, quotient of sixty three and seven, seven divided into sixty three
1.5.350) seventy two divided by eight, quotient of seventy two and eight, eight divided into seventy two
1.5.351)
□□□□□ □□□□□ □□□□□
5 5 5
15 total
1.5.352)
□□□□□ □□□□□
5 5
10 total
1.5.353)
□□□□□□□ □□□□□□□
7 7
14 total
1.5.354)
□□□□□□ □□□□□□ □□□□□□
6 6 6
18 total
1.5.355)
□□□□ □□□□ □□□□ □□□□ □□□□
4 4 4 4 4
20 total
1.5.356)
□□□ □□□ □□□ □□□ □□□
3 3 3 3 3
15 total
1.5.357)
□□□□□□ □□□□□□ □□□□□□ □□□□□□
6 6 6 6
24 total
1.5.358)
□□□□ □□□□ □□□□ □□□□
4 4 4 4
16 total
1.5.359) 18/2=9, 9*2=18
1.5.360) 14/2=7, 7*2=14
1.5.361) 27/3=9, 9*3=27
1.5.362) 30/3=10, 10*3=30
1.5.363) 28/4=7, 7*4=28
1.5.364) 36/4=9, 9*4=36
1.5.365) 45/5=9, 9*5=45
1.5.366) 35/5=7, 7*5=35
1.5.367) 72/8=9, 9*8=72
1.5.368) 64/8=8, 8*8=64
1.5.369) 35/7=5, 5*7=35
1.5.370) 42/7=6, 6*7=42
1.5.371) 15/15=1, 1*15=15
1.5.372) 12/12=1, 1*12=12
1.5.373) 43/43=1, 1*43=43
1.5.374) 37/37=1, 1*37=37
1.5.375) 23/1=23, 23*1=23
1.5.376) 29/1=29, 29*1=29
1.5.377) 19/1=19, 19*1=19
1.5.378) 17/1=17, 17*1=17
1.5.379) 0/4=0, 0*4=0
1.5.380) 0/8=0, 0*8=0
1.5.381) 5/0=undefined
1.5.382) 9/0=undefined
1.5.383) 26/0=undefined
1.5.384) 32/0=undefined
1.5.385) 0/12=0, 12*0=0
1.5.386) 0/36=0, 36*0=0
1.5.387) 72/3=24, 3*24=72
1.5.388)
1.5.389)
1.5.390)
1.5.391)
1.5.392)
1.5.393)
1.5.394)
1.5.395)
1.5.396)
1.5.397)
1.5.398)
1.5.399)
1.5.400)
1.5.401)
1.5.402)
1.5.403)
1.5.404)
1.5.405)
1.5.406)
1.5.407)
1.5.408)
3738+3=3741
1.5.409)
55304+1=55305
1.5.410)
51489+3=51492
1.5.411)
431170+4=431174
1.5.412)
297276+1=29727
1.5.413)
130014+2=130016
1.5.414)
105608+1=105609
1.5.415)
5730+5=5735
1.5.416)
4914+19=4933
1.5.417)
1.5.418)
1.5.419)
1.5.420)
1.5.421)
542178+17=542195
1.5.422)
815892+351=816243
1.5.423)
1.5.424)
1.5.425)
1.5.426)
1.5.427)
1.5.428)
1.5.429)
1.5.430)
1.5.431) 45/15=3
1.5.432) 64/16=4
1.5.433) 288/24=12
1.5.434) 256/32=8
1.5.435) 64/2=32
1.5.436) 42/3=14
1.5.437) 125/5=25
1.5.438) 152/8=19
1.5.439) 48/3=16
1.5.440) 54/2=28
1.5.441) 45-17=28
1.5.442) 71-53=18
1.5.443) 45/9=5
1.5.444) 128/4=32
1.5.445) 8+14+11+17=50
1.5.446) 6+26+15+9=56
1.5.447) 12*4=48
1.5.448) 14*5=120
1.5.449) one is the inverse of another.
long division seems to be the inverse of vertical multiplication.
1.5.450) multiple 8 by 37 and add 4, the result should be 800
1.5.451)
1.5.452)
TRY IT
2.1)
2.2)
2.3)
2.4)
2.5)
2.6)
2.7)
2.8)
2.9)
2.10)
2.11)
2.12)
2.13)
2.14)
2.15)
2.16)
2.17) 42/7*3 = 6*3 = 18
2.18) 12*3/4 = 36/4 = 9
2.19) 30/5+10(3-2) = 30/5+10(1) = 30/5+10(1) = 6+10(1) = 6+10 = 16
2.20) 70/10+4(6-2) = 70/10+4(4) = 7/1+4(4) = 7+4(4) = 7+16 = 23
2.21) 9+5^3-(4(9+3)) = 9+5^3-(4(11)) = 9+5^3-(44) = 9+5^3-44 = 9+125-44 = 134-44 = 90
2.22) 7^2-2(4(5+1)) = 7^2-2(4(6)) = 7^2-2(24) = 49-2(24) = 49-48 = 1
2.23) 3^2 + 2^4 / 2 + 4^3 = 9+16/2+48 = 9+8+48 = 17+48 = 65
2.24) 6^2 - 5^3 / 5 + 8^2 = 36 - 125 / 5 + 64 = 36-25+64 = 61+64 = 125
EXERCISE
2.1.1) 16 minus 9; difference of 16 and 9; subtract 9 from 16
2.1.2) 25 minus 7; difference of 27 and 7; subtract 7 from 25
2.1.3) 5 times 6; product of 5 and 6; 5 multiplied by 6
2.1.4) 3 times 9; product of 3 and 9; 3 multiplied by 9
2.1.5) 28 divided by 4; quotient of 24 and 8; 24 divided by 8; 24 divided into 8
2.1.6) 45 divided by 5; quotient of 45 and 5; 45 divided bt 5; 5 divided into 45
2.1.7) x plus 8; sum of x and 8
2.1.8) x plus 11; sum of x and 11
2.1.9) 2 times 7; product of 2 and 7
2.1.10) 4 times 8; product of 4 and 8
2.1.11) 14 is less than 21
2.1.12) 17 is less than 35
2.1.13) 36 is greater than or equal to 19
2.1.14) 42 is greater than or equal to 27
2.1.15) 3 times n is equal to 24
2.1.16) 6 times n is equal to 36
2.1.17) y minus 1 is greater than 6
2.1.18) y minus 4 is greater than 8
2.1.19) 2 is less than or equal to 18 divided by 6
2.1.20) 3 is less than or equal to 20 divided by 4
2.1.21) a is not equal to 7 times 4
2.1.22) a is not equal to 1 times 12
2.1.23) equation
2.1.24) equation
2.1.25) expression
2.1.26) expression
2.1.27) expression
2.1.28) expression
2.1.29) equation
2.1.30) expression
2.1.31) 3^7
2.1.32) 4^6
2.1.33) x^5
2.1.34) y^6
2.1.35) 5*5*5
2.1.36) 8*8*8
2.1.37) 2*2*2*2*2*2*2*2
2.1.38) 10*10*10*10*10
2.1.39)
2.1.40)
2.1.41) 2^3-12/(9-5) = 2^3-12/4 = 8-12/4 = 8-3 = 5
2.1.42) 3^2-18/(11-5) = 3^2-18/6 = 9-18/6 = 9-3 = 6
2.1.43) 3*8+5*2 = 3*8+10 = 3*8+10 = 24+10 = 34
2.1.44) 4*7+3*5 = 28+3*5 = 28+15 = 43
2.1.45) 2+8(6+1) = 2+8(7) = 2+56 = 58
2.1.46) 4+6(3+6) = 4+6(9) = 4+54 = 58
2.1.47) 4*12/8 = 48/8 = 6
2.1.48) 2*36/6 = 2*6 = 12
2.1.49) 6+10/2+2 = 6+5+2 = 13
2.1.50) 9+12/3+4 = 9+4+4 = 17
2.1.51) (6+10)/(2+2) = 16/4 = 4
2.1.52) (9+12)/(3+4) = 21/7 = 3
2.1.53) 20/4+6*5 = 5+30 = 35
2.1.54) 33/3+8*2 = 11+16 = 27
2.1.55) 20/(4+6)*5 = 20/10*5 = 2*5 = 10
2.1.56) 33/(3+8)*2 = 33/11*2 = 3*2 = 6
2.1.57) 4^2+5^2 = 16+25 = 41
2.1.58) 3^2+7^2 = 9+49 = 58
2.1.59) (4+5)^2 = 9^2 = 81
2.1.60) (3+7)^2 = 10^2 = 100
2.1.61) 3(1+9*6)-4^2 = 3(1+54)-4^2 = 3*55-4^2 = 3*55-16 = 165
2.1.62) 5(2+8*4)-7^2 = 5(2+32)-7^2 = 5*34-7^2 = 5*34-49 = 170-49 = 121
2.1.63) 2(1+3(10-2)) = 2(1+3(8)) = 2(1+24) = 2*25 = 50
2.1.64) 5(2+4(3-2)) = 5(2+4(1)) = 5(2+4) = 5(6) = 40
2.1.65)
2.1.66)
2.1.67) expression is a hierarchy of math operations, evaluation is the relationship between 2 expressions
2.1.68) it's so simplifying an expression always results in the same answer
TRY IT
2.25) y+4
2.26) a-5
2.27) 8x-3
2.28) 4y-4
2.29) x^2 -- when x=8, 8^2=64
2.30) x^3 -- when x = 6, 6^3=108
2.31) 2^x -- when x = 6, 2^6=64
2.32) 3^x -- when x = 4, 3^4=81
2.33) 2x+5y-4 -- when x = 11 and y = 13, 2(11)+5(4)-4 = 22+20-4 = 22+16 = 38
2.34) 5x-2y-9 -- when x = 7 and y = 8, 5(7)-2(8)-9 = 35-16-9 = 35-7 = 28
2.35) 3x^2+4x+1 -- x=3, 3(3)^2+4(3)+1 = 3(9)+4(3)+1 = 27+12+1 = 27+13 = 40
2.36) 6x^2-4x-7 -- x=2, 6(2)^2-4(2)-7 = 6(4)-4(2)-7 = 24-8-7 = 23
2.37) 4x + 3b + 2 has the terms...
2.38) 9a + 13a^2 + a^3 has the terms 9a, 13a^2, a^3
2.39) like terms in 9, 2x^3, y^2, 8x^3, 15, 9y, 11y^2...
2.40) like terms in the expression 4x^3+8x^2+19+3x^2+24+6x^3 ...
2.41) 7x+9+9x+8 simplifies to 16x+17
2.42) 5y+2+8y+4y+5 simplifies to 17y+7
2.43) 3x^2+9x+x^2+5x simplifies to 4x^2+14x
2.44) 11y^2+8y+y^2+7y simplifies to 12y^2+15y
2.45)
2.46)
2.47)
2.48)
2.49)
2.50)
2.51) l = w-5
2.52) w = 2 + l
2.53) d = 5q-7
2.54) d = 8 + 4n
EXERCISE
2.2.69) 7(2)+8 = 14+8 = 22
2.2.70) 9(3)+7 = 27+7 = 34
2.2.71) 5(6)-4 = 30-4 = 26
2.2.72) 8(7)-6 = 56-6 = 50
2.2.73) 12^2 = 144
2.2.74) 5^3 = 125
2.2.75) 2^5 = 32
2.2.76) 3^4 = 81
2.2.77) 3^3 = 27
2.2.78) 4^2 = 16
2.2.79) 4^2 + 3*4 - 7 = 16 + 12 - 7 = 28 - 7 = 21
2.2.80) 6^2 + 5*6 - 8 = 36 + 30 - 8 = 66 - 8 = 58
2.2.81) 2*7 + 4*8 - 5 = 14 + 32 - 9 = 46 - 9 = 37
2.2.82) 6*6 + 3*9 - 9 = 36 + 27 - 9 = 36 + 18 = 54
2.2.83) (10-7)^2 = 3^2 = 9
2.2.84) (6+9)^2 = 15^2 = 225
2.2.85) 3^2 + 8^2 = 9 + 64 = 73
2.2.86) 12^2 - 5^2 = 144 - 25 = 119
2.2.87) 2(15) + 2(12) = 30 + 24 = 54
2.2.88) 2(18) + 2(14) = 36 + 28 = 64
2.2.89) 15x^2, 6x, 2
2.2.90) 11x^2, 8x, 5
2.2.91) 10y^3, y, 2
2.2.92) 9y^3, y, 5
2.2.93) 8
2.2.94) 13
2.2.95) 5
2.2.96) 6
2.2.97) {x^3, 8x^3}, {8x}, {14, 5}, {8y}
2.2.98) {6z, 4z}, {3w^2, w^2}, {1}, {6z^2}
2.2.99) {9a}, {a^2}, {16ab, 4ab}, {16b^2, 9b^2}
2.2.100) {3}, {25r^2, 4r^2}, {10s, 3s}, {10r}
2.2.101) 13x
2.2.102) 19x
2.2.103) 26a
2.2.104) 27z
2.2.105) 7c
2.2.106) 11y
2.2.107) 12x+8
2.2.108) 13a+9
2.2.109) 10u+3
2.2.110) 10d+11
2.2.111) 12p+10
2.2.112) 12x-2
2.2.113) 22a+1
2.2.114) 22c+0=22c
2.2.115) 17x^2+20x+16
2.2.116) 7b^2+12b+6
2.2.117) 8+12
2.2.118) 9+1
2.2.119) 14-9
2.2.120) 19-8
2.2.121) 9*7
2.2.122) 8*7
2.2.123) 36/9
2.2.124) 42/7
2.2.125) x-4
2.2.126) x-3
2.2.127) 6*y
2.2.128) 9*y
2.2.129) 8x+3x
2.2.130) 13x+3x
2.2.131) y/3
2.2.132) y/8
2.2.133) 8*(y-9)
2.2.134) 7*(y-1)
2.2.135) 5*(x+y)
2.2.136) 2x-(9*5)
2.2.137) s = b + 15
2.2.138) r = 3 + c
2.2.139) g = b - 4
2.2.140) m = f - 6
2.2.141) p = 2n-7
2.2.142) f = 3+6t
2.2.143) justin pays 750, insurance company pays 2100-750
2.2.144) pam and armando pay 2500, insurance pays 19400-2500
2.2.145) addition has commutative property, subtraction doesn't
2.2.146) the operators in each expression are different -- 4(x+y) vs 4x+y
TRY IT
2.55)
2.56)
2.57)
2.58)
2.59) x+1=7
2.60) x+3=4
2.61)
2.62)
2.63)
2.64)
2.65)
2.66)
2.67)
2.68)
2.69) 7+6=13
2.70) 8+6=14
2.71) 6*9=54
2.72) 21*3=63
2.73) 2(x-5)=30
2.74) 2(y-4)=16
2.75)
2.76)
2.77)
2.78)
EXERCISE
2.3.147) a
2.3.148) a
2.3.149) b
2.3.150) b
2.3.151) a
2.3.152) a
2.3.153) b
2.3.154) b
2.3.155) b
2.3.156) b
2.3.157) b
2.3.158) b
2.3.159) x+2=5
2.3.160) 4+x=7
2.3.161) 3+x=6
2.3.162) 5+x=9
2.3.163)
2.3.164)
2.3.165)
2.3.166)
2.3.167)
2.3.168)
2.3.169)
2.3.170)
2.3.171)
2.3.172)
2.3.173)
2.3.174)
2.3.175)
2.3.176)
2.3.177)
2.3.178)
2.3.179)
2.3.180)
2.3.181)
2.3.182)
2.3.183)
2.3.184)
2.3.185)
2.3.186)
2.3.187) 8+9=17
2.3.188) 7+9=16
2.3.189) 23-19=4
2.3.190) 29-12=17
2.3.191) 3*9=27
2.3.192) 6*8=48
2.3.193) 54/6=9
2.3.194) 42/7=6
2.3.195) 2(n-10)=52
2.3.196) 2(m-14)=64
2.3.197) (3y)+10=100
2.3.198) (8x)+4=68
2.3.199)
2.3.200)
2.3.201)
2.3.202)
2.3.203)
2.3.204)
2.3.205)
2.3.206)
2.3.207)
2.3.208)
2.3.209)
2.3.210)
2.3.211)
2.3.212)
2.3.213)
no -- 2*1 != 18
2.3.214)
the difference of y and 5 is 21 -- NAME had paid 21 dollars in total for PRODUCT after receiving a 5 dollar discount. What was the original price of PRODUCT?
TRY IT
2.79)
2.80)
2.81)
2.82)
2.83)
2.84)
2.85)
2.86)
2.87) 6240
2.88) 7248
2.89) 4962
2.90) 3765
2.91)
2.92)
2.93)
2.94)
EXERCISE
2.4.215)
2.4.216)
2.4.217)
2.4.218)
2.4.219)
2.4.220)
2.4.221)
2.4.222)
2.4.223)
2.4.224)
2.4.225) 84
2.4.226) 96
2.4.227) 75
2.4.228) 78
2.4.229) 168
2.4.230) 264
2.4.231) 900
2.4.232) 800
2.4.233) 896
2.4.234) 942
2.4.235) 375
2.4.236) 750
2.4.237) 350
2.4.238) 550
2.4.239) 1430
2.4.240) 1080
2.4.241) 22335
2.4.242) 39075
2.4.243)
2.4.244)
2.4.245)
2.4.246)
2.4.247)
2.4.248)
2.4.249)
2.4.250)
2.4.251)
43 is prime, its only factors are 1 and itself
2.4.252)
67 is prime, its only factors are 1 and itself
2.4.253)
39 is composite -- it's divisible by 3 (see common divisibility tests), which means it has over 2 factors(1, itself, 3, and maybe more)
2.4.254)
53 is prime, its only factors are 1 and itself
2.4.255)
71 is prime, its only factors are 1 and itself
2.4.256)
119 is composite
2.4.257)
481 is composite
2.4.258)
221 is composite
2.4.259)
209 is composite
2.4.260)
359 is prime
2.4.261)
2.4.262)
2.4.263)
2.4.264)
2.4.265)
6 is a composite of 2 and 3, meaning that 6 has the factors 2 and 3 -- 6=2*3.
Multiplying any number by 6 is the same as multiplying it by 2*3. For example, 10*6=60, 10*2*3=60. Since you're multiplying by both 2 and 3, the product is divisible by both 2 and 3.
10*2*3=60 can be reordered as (10*2)*3=60, then simplified to 20*3=60 -- meaning 60 is divisible by 3
10*2*3=60 can be reordered as (10*3)*2=60, then simplified to 30*2=60 -- meaning 60 is divisible by 3
2.4.266)
A prime number has 2 factors -- 1 and itself
A composite number as more than 2 factors -- 1, itself, and others
1 is neither a prime nor a composite since it only has 1 factor: itself.
TRY IT
2.95)
80 = 2*2*2*2*5
2.96)
60 = 2*2*3*5
2.97)
126 = 2*3*3*7
2.98)
294 = 2*3*7*7
2.99)
5
2)10
2)20
2)40
2)80
80 = 2*2*2*2*5
2.100)
5
3)15
2)30
2)60
60 = 2*2*3*5
2.101)
3
7)21
3)63
2)126
126 = 2*3*3*7
2.102)
7
7)49
3)147
2)294
294 = 2*3*7*7
2.103)
2.104)
2.105)
factor tree for 15...
factor tree for 20...
merge prime factors: 2*2*3*5 = 60
2.106)
factor tree for 15...
factor tree for 35...
merge prime factors: 3*5*7 = 105
2.107)
factor tree for 55...
factor tree for 88
merge prime factors: 2*2*2*5*11 = 440
2.108)
factor tree for 60...
factor tree for 72...
merge prime factors: 2*2*2*3*3*5=360
EXERCISE
2.5.267)
2.5.268)
2.5.269)
2.5.270)
2.5.271)
2.5.272)
2.5.273)
2.5.274)
2.5.275)
2.5.276)
2.5.277)
7
2)14
2)28
2)56
2.5.278)
3
3)9
2)18
2)36
2)72
2.5.279)
7
3)21
2)42
2)84
2)168
2.5.280)
7
3)21
3)63
2)126
2)252
2.5.281)
23
17)391
2.5.282)
5
5)25
2)50
2)100
2)200
2)400
2.5.283)
9
3)27
2)54
2)108
2)216
2)432
2.5.284)
19
11)209
3)627
2.5.285)
5
2)10
3)30
3)90
3)270
2)540
2)1080
2)2160
2.5.286)
7
5)35
3)105
3)315
2)630
2)1260
2)2520
2.5.287)
2.5.288)
2.5.289)
2.5.290)
2.5.291)
2.5.292)
2.5.293)
2.5.294)
2.5.295)
2.5.296)
2.5.297)
2.5.298)
2.5.299)
2.5.300)
2.5.301)
2.5.302)
2.5.303)
prime factors of 8...
prime factors of 12...
merged factors (lcm): 2*2*2*3=24
2.5.304)
prime factors of 12...
prime factors of 16...
merged factors (lcm): 2*2*2*2*3=48
2.5.305)
prime factors of 24...
prime factors of 30...
merged factors (lcm): 2*2*2*3*5=120
2.5.306)
prime factors of 28...
prime factors of 40...
merged factors (lcm): 2*2*2*5*7=280
2.5.307)
prime factors of 70...
prime factors of 84...
merged factors (lcm): 2*2*3*5*7=420
2.5.308)
prime factors of 84...
prime factors of 90...
merged factors (lcm): 2*2*3*3*5*7=1260
2.5.309)
prime factors of 6...
prime factors of 21...
merged factors (lcm): 2*3*7=42
2.5.310)
prime factors of 9...
prime factors of 15...
merged factors (lcm): 3*3*5=45
2.5.311)
prime factors of 24...
prime factors of 30...
merged factors (lcm): 2*2*2*3*5=120
2.5.312)
lcm is 160
2.5.313)
10 hotdogs in a package
8 hotdog buns in a package
2*2*2*5=40 -- if I didn't want to have any remaining hotdogs / hotdog buns (I wanted exactly 1 hotdog per hotdog bun), the minimum I'd have is 40 indiviudal hotdogs and hotdog buns.
The LCM is 40.
10hotdogs per package * 4packages = 40hotdogs
8hotdog buns per package * 5packages = 40hotdog buns
2.5.314)
12 paper plates in a package
8 cups in a package
2*2*2*3=24 -- if I didn't want to have any remaining paper plates / cups (I wnated exactly 1 paper plate per cup), the minimum I'd have is 24 individual plates and cups.
The LCM is 24.
12plates per package * 2 packages = 24plates
8cups per package * 3packages = 23cups
2.5.315) prefer factor tree because I don't have to think what the next prime is -- when I see it on a leaf node I usually know right away
2.5.316) prime factors because listing multiples may go on for a long time.
TRY IT
3.1)
a)
<--|--|--|--|--|--*--|--|--|-->
-4 -3 -2 -1 0 1 2 3 4
b)
<--|--|--|--*--|--|--|--|--|-->
-4 -3 -2 -1 0 1 2 3 4
c)
<--*--|--|--|--|--|--|--|--|-->
-4 -3 -2 -1 0 1 2 3 4
3.2)
a)
<--*--|--|--|--|--|--|--|--|-->
-4 -3 -2 -1 0 1 2 3 4
b)
<--|--|--|--|--|--|--|--|--*-->
-4 -3 -2 -1 0 1 2 3 4
c)
<--|--|--|--*--|--|--|--|--|-->
-4 -3 -2 -1 0 1 2 3 4
3.3)
3.4)
3.5)
3.6)
3.7) -(-1) = 1
3.8) -(-5) = 5
3.9)
3.10)
3.11)
3.12)
3.13)
3.14)
3.15)
3.16)
3.17)
3.18)
3.19) |1+8|-|2+5| = |9|-|7| = 9-7 = 2
3.20) |9-5|-|7-6| = |4|-|1| = 4-1 = 3
3.21) 19-|11-4(3-1)| = 19-|11-4(2)| = 19-|11-8| = 19-|3| = 19-3 = 16
3.22) 9-|8-4(7-5)| = 9-|8-4(2)| = 9-|8-8| = 9-|0| = 9-0 = 9
3.23)
3.24)
3.25) gain means positive, so 5 yards
3.26) below means negative, so -30 feet
EXERCISE
3.1.1)
a)
<--|--|--|--|--|--|--|--|--|--|--*--|--|--|--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
b)
<--|--|--|--|--|--|--*--|--|--|--|--|--|--|--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
c)
<--|--|--|--*--|--|--|--|--|--|--|--|--|--|--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
3.1.2)
a)
<--|--|--|--|--|--|--|--|--|--|--|--|--|--*--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
b)
<--|--|--|--*--|--|--|--|--|--|--|--|--|--|--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
c)
<--|--|--|--|--|--|--*--|--|--|--|--|--|--|--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
3.1.3)
a)
<--*--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
b)
<--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--*-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
c)
<--|--|--*--|--|--|--|--|--|--|--|--|--|--|--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
3.1.4)
a)
<--|--*--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
b)
<--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--*--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
c)
<--|--|--|--|--|--|--|--*--|--|--|--|--|--|--|--|--|-->
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
3.1.5)
3.1.6)
3.1.7)
3.1.8)
3.1.9)
3.1.10)
3.1.11)
3.1.12)
3.1.13) 4
3.1.14) 8
3.1.15) 15
3.1.16) 11
3.1.17)
3.1.18)
3.1.19)
3.1.20)
3.1.21)
3.1.22)
3.1.23)
3.1.24)
3.1.25)
3.1.26)
3.1.27)
3.1.28)
3.1.29)
3.1.30)
3.1.31)
3.1.32)
3.1.33) |8-4| = |4| = 4
3.1.34) |9-6| = |3| = 3
3.1.35) 8|-7| = 8(7) = 56
3.1.36) 5|-5| = 5(5) = 25
3.1.37) |15-7|-|14-6| = |8|-|8| = 8-8 = 0
3.1.38) |17-8|-|13-4| = |9|-|9| = 9-9 = 0
3.1.39) 18-|2(8-3)| = 18-|2(5)| = 18-|10| = 18-10 = 8
3.1.40) 15-|3(8-5)| = 15-|3(3)| = 15-|9| = 15-9 = 6
3.1.41) 8(14-2|-2|) = 8(14-2(2)) = 8(14-4) = 8(10) = 80
3.1.42) 6(13-4|-2|) = 6(13-4(2)) = 6(13-8) = 6(5) = 30
3.1.43)
3.1.44)
3.1.45)
3.1.46)
3.1.47) 6 below zero, -6
3.1.48) 14 below zero, -14
3.1.49) 40 below sea level, -40
3.1.50) 65 below sea level, -65
3.1.51) loss of 12 yards. -12
3.1.52) gain of 4 years, 4
3.1.53) gain of 3, 3
3.1.54) loss of 5, -5
3.1.55) one above par, 1
3.1.56) 3 below par, -3
3.1.57)
3.1.58)
3.1.59)
3.1.60)
3.1.61) temp today is -2 celcius (2 below 0)
3.1.62) - is used for...
TRY IT
3.27)
xx xxxx
2 4
3.28)
xx xxxxx
2 5
3.29)
oo oooo
-2 -4
3.30)
oo ooooo
-2 -5
3.31)
xx 2
oooo -4
-2 remaining
3.32)
xx 2
ooooo -5
-3 remaining
3.33)
xxxx 4
oo -2
2 remaining
3.34)
xxxxx 5
oo -2
3 remaining
3.35)
a)
xxx xxxx
3 4
7 total
b)
xxxx 4
o -1
3 remaining
c)
xxxx 4
oooooo -6
-2 remaining
d)
oo oo
-2 -2
-4 total
3.36)
a)
xxxxx x
5 1
6 total
b)
xxxxxxx 7
ooo -3
4 remaining
c)
xx 2
oooooooo -8
6 remaining
d)
ooo oooo
-3 -4
-7 total
3.37)
3.38)
3.39) -31 + (-19) = -50
3.40) -42 + (-28) = -70
3.41)
3.42)
3.43)
3.44)
3.45)
3.46)
3.47)
3.48)
3.49)
3.50)
3.51)
3.52)
3.53)
3.54)
3.55) -10 + 14 = 6
3.56) -16 + -17 = -33
3.57) 20 + -9 + 7 + -4 = 14
3.58) 25 + 5 + -8 + 15 = 37
EXERCISE
3.2.63) 7 + 4 = 11
ppppppp pppp
3.2.64) 8 + 5 = 13
pppppppp ppppp
3.2.65) -6 + -5 = -11
nnnnnn nnnnn
3.2.66) -5 + -5 = -10
nnnnn nnnnn
3.2.67) -7 + 5 = -2
nnnnnnn
ppppp
3.2.68) -9 + 6 = -3
nnnnnnnnn
pppppp
3.2.69) 8 + -7 = 1
pppppppp
nnnnnnn
3.2.70) 9 + -4 = 5
ppppppppp
nnnn
3.2.71) -21 + -59 = -80
3.2.72) -35 + -47 = -92
3.2.73) 48 + -16 = 32
3.2.74) 34 + 19 = 15
3.2.75) -200 + 65 = 135
3.2.76) -150 + 45 = 105
3.2.77) 2 + -8 + 6 = 0
3.2.78) 4 + -9 + 7 = 11
3.2.79) -14 + -12 + 4 = -22
3.2.80) -17 + -18 + 6 = -29
3.2.81) 135 + -110 + 83 = 25 + 83 = 108
3.2.82) 140 + -75 + 67 = 132
3.2.83) -32 + 24 + -6 + 10 = -8 + 4 = 4
3.2.84) -38 + 27 + -8 + 12 = 11 + 4 = 15
3.2.85) 19 + 2(-3 + 8) = 19 + 2(5) = 19 + 10 = 29
3.2.86) 24 + 3(-5 + 9) = 24 + 3(4) = 24 + 12 = 36
3.2.87)
3.2.88)
3.2.89)
3.2.90)
3.2.91)
3.2.92)
3.2.93)
3.2.94)
3.2.95) -15 + 7 = 8
3.2.96) -9 + 17 = 8
3.2.97) 16 - 3(2) = 16 - 6 - 10
3.2.98) 2(-6) + -5 = -6 + -6 + -5 = -17
⚠️NOTE️️️⚠️
2(-6) is the same as -6 + -6
3.2.99) (-7 + 15)^2 = (8)^2 = 64
3.2.100) (-5 + 14)^2 = (9)^2 = 81
3.2.101) (-3 + 14)^2 = (11)^2 = 121
3.2.102) (-3 + 15)^2 = (12)^2 = 144
3.2.103) -14 + 5 = 9
3.2.104) -22 + 9 = -13
3.2.105) 8 + -2 = 6
3.2.106) 5 + -1 = 4
3.2.107) -10 + -15 = -25
3.2.108) -6 + -20 = -26
3.2.109) 6 + (-1 + -12) = -7
3.2.110) 3 + (-2 + -8) = -7
3.2.111) (10 + -19) + 4 = -5
3.2.112) (12 + -15) + 1 = -2
3.2.113) -19 + 26 = 7
3.2.114) -15 + 28 = 13
3.2.115) -73 + -45 = 118
3.2.116) -212 + -105 = -317
3.2.117) -3 + 2 + -1 = -2
3.2.118) -5 + -3 + 2 + -1 = -7
3.2.119) 35 + -12 + 8 + -6 = 25
3.2.120) 20 + 15 + -3 + 6 = 38
3.2.121) -90 + 110 = 20
3.2.122) -168 + 140 = -28
3.2.123) -504 + 142 + -449 + 410 + 369 = -32
3.2.124) -201 + -16 + -23 + 172 + -34 = -102
3.2.125) you can model it out
-8 + 2 is ...
pp
nnnnnnnn
there are 6 more negatives than there are positives, the answer is -6
8 + -2 is ...
pppppppp
nn
there are 6 more positives than there are negatives, the answer is 6
3.2.126) technical diving -- when you're 100 feet under water and you go down another 10 feet.. -100 + -10
TRY IT
3.59)
pppppp 6
┌──────┐
pp │ pppp │ 6 - 4
└──────┘
3.60)
ppppppp 7
┌──────┐
ppp │ pppp │ 7 - 4
└──────┘
3.61)
nnnnnn 6
┌──────┐
nn │ nnnn │ 6 - 4
└──────┘
3.62)
nnnnnnn 7
┌──────┐
nnn │ nnnn │ 7 - 4
└──────┘
3.63)
nnnnnn -6
pppp 4
-6 - 4
no ps to subtract from the ns, so add an n for each p..
nnnnnn[nnnn]
pppp
-10
3.64)
nnnnnnn -7
pppp 4
-7 - 4
no ps to subtract from the ns, so add an n for each p..
nnnnnnn[nnnn]
pppp
-11
3.65)
pppppp 6
nnnn -4
no ns to subtract from the ps, so add a p for each n..
pppppp[pppp]
nnnn
10
3.66)
ppppppp[pppp]
nnnn
11
3.67)
a)
ppppppp[pppppppp]
nnnnnnnn
15
b)
nn[] -2
nn -2
0
c)
ppp[pppp] 7
ppp 3
4
d)
nnnnnn[pp]
nnnnnn nn
2
3.68)
a)
pppp[pppppp]
nnnnnn
10
b)
[nnnnnnn]n
-7
c)
[nnnnnnn]n
-7
d)
nnnn[nn]
pp
6
3.69)
a) 7 - 9
ppppppp
nnnnnnnnn <-- neutralize by adding 9 negatives, we have more negatives that positives
-2
b) -5 - (-9)
nnnnn
ppppppppp <-- neutralize by adding 10 positives, we have more positives than negatives
4
3.70)
a) 4 - 7
pppp
nnnnnnn <-- neutralize by adding 9 negatives, we have more negatives than positives
-3
b) -7 - (-10)
nnnnnnn
pppppppppp <-- neutralize by adding 10 positives, we have more positives than negatives
3
3.71)
3.72)
3.73)
3.74)
3.75) -67 - (-38) = 29
3.76) -83 - (-57) = 26
3.77) 8 - (-3 - 1) - 9 = 8 - (-4) - 9 = 12 - 9 = 3
3.78) 12 - (-9 - 6) - 14 = 12 - (-15) - 14 = 27 - 14 = 13
3.79) 6(2) - 9(1) - 8(9) = 12 - 9 - 72 = 3 - 72 = -69
3.80) 2(5) - 3(7) - 4(9) = 10 - 21 - 36 = -11 - 36 = -47
3.81)
3.82)
3.83)
3.84)
3.85)
3.86)
3.87) 15 - -30 = 45
3.88) -5 - -16 = 11
3.89) 10023 - -80 = 10103
3.90) -340 - -573 = 233
3.91)
3.92)
EXERCISE
3.3.127) 8 - 2 = 6
pppppppp
nn
6 ps remaining
3.3.128) 9 - 3 = 6
ppppppppp
nnn
3 more ps remaining
3.3.129) -5 - -1 = -4
nnnn[n]
after removing 1 n, 4 ns remaining
3.3.130) -6 - -4
nn[nnnn]
after removing 4 n, 2 ns remaining
3.3.131) -5 - 4
nnnnnnnnn
pppp
no ps to subtract from the ns, so add an n for each p.. 9 ns
3.3.132) -7 - 2
nnnnnnnnn
pp
no ps to subtract from the ns, so add an n for each p.. 9 ns
3.3.133) 8 - -4
pppppppppppp
nnnn
no ns to subtract from the ps, so add a p for each n.. 12 ps
3.3.134) 7 - (-3)
pppppppppp
nnn
no ns to subtract from the ps, so add a p for each n.. 10 ps
3.3.135)
3.3.136)
3.3.137)
3.3.138)
3.3.139)
3.3.140)
3.3.141)
3.3.142)
3.3.143) 15 - (-12) = 27
3.3.144) 14 - (-11) = 25
3.3.145) 10 - (-19) = 29
3.3.146) 11 - (-18) = 29
3.3.147) 48 - 87 = -39
3.3.148) 45 - 69 = -24
3.3.149) 31 - 79 = -48
3.3.150) 39 - 81 = -42
3.3.151) -31 - 11 = -42
3.3.152) -32 - 18 = -50
3.3.153) -17 - 42 = -59
3.3.154) -19 - 46 = -65
3.3.155) -103 - (-52) = -51
3.3.156) -105 - (-68) = -37
3.3.157) -45 - (-54) = 9
3.3.158) -58 - (-67) = -9
3.3.159) 8 - 3 - 7 = 5 - 7 = -2
3.3.160) 9 - 6 - 5 = 4 - 5 = -1
3.3.161) -5 - 4 + 7 = -9 + 7 = -2
3.3.162) -3 - 8 + 4 = -11 + 4 = -7
3.3.163) -14 - (-27) + 9 = 13 + 9 = 22
3.3.164) -15 - (-28) + 5 = 13 + 5 = 18
3.3.165) 71 + (-10) - 8 = 61 - 8 = 53
3.3.166) 64 + (-17) - 9 = 47 - 9 = 38
3.3.167) -16 - (-4 + 1) - 7 = -16 - (-3) - 7 = -13 - 7 = -20
3.3.168) -15 - (-6 + 4) - 3 = -15 - (-2) - 3 = -13 - 3 = -16
3.3.169) (2 - 7) - (3 - 8) = -5 - -5 = 0
3.3.170) (1 - 8) - (2 - 9) = -7 - -7 = 0
3.3.171) -(6 - 8) - (2 - 4) = -(-2) - (-2) = 2 - -2 = 4
3.3.172) -(4 - 5) - (7 - 8) = -(-1) - (-1) = 1 - (-1) = 2
3.3.173) 25 - [10 - (3 - 12)] = 25 - [10 - -9] = 25 - 19 = 6
3.3.174) 32 - [5 - (15 - 20)] = 32 - [5 - -5] = 32 - 10 = 42
3.3.175) 6.3 - 4.3 - 7.2 = 2 - 7.2 = -5.2 --- WHY ASK THIS? THE BOOK HASN'T COVERED DECIMAL NUMBERS YET
3.3.176) 5.7 - 8.2 - 4.9 = -2.5 - 4.9 = -7.4 --- WHY ASK THIS? THE BOOK HASN'T COVERED DECIMAL NUMBERS YET
3.3.177) 5^2 - 6^2 = 25 - 36 = -11
3.3.178) 6^2 - 7^2 = 36 - 49 = -13
3.3.179)
3.3.180)
3.3.181)
3.3.183) 4(3)^2 - 15(3) + 1 = 4(9) - 45 + 1 = 36 - 45 + 1 = -9 + 1 = -8
3.3.184) 5(2)^2 - 14(2) + 7 = 5(4) - 28 + 7 = 20 - 28 + 7 = -8 + 7 = -1
3.3.185) -12 - 5(6)^2 = -12 - 5(36) = -12 - 180 = -192
3.3.186) -19 - 4(5)^2 = -19 - 4(25) = -19 - 100 = -119
3.3.187)
3.3.188)
3.3.189)
3.3.190)
3.3.191)
3.3.192)
3.3.193)
3.3.194)
3.3.195) 28 - 38 = -10
3.3.196) 22 - 35 = -13
3.3.197) 84 - -12 = 96
3.3.198) 89 - -31 = 120
3.3.199) 30 + 2 - 7 - 4 = 21
3.3.200) 20 - 8 + 5 - 6 = 11
3.3.201) 148 - 83 = 65
3.3.202) 426 - 152 = 274
3.3.203) 210 - 250 = -40
3.3.204) 94 - 110 = -16
3.3.205) -14 + 40 = -26
3.3.206) -23 + 80 = -57
3.3.207) -20 - -7 = -13
3.3.208) -100 - -45 = -55
3.3.209) 9 to 0 is 9, 0 to -6 is 6 -- 9 + 6 is 15
3.3.210) when you subtract a negative, you go right on the number line by that amount -- you also go right on the number line when you add some amount.
TRY IT
3.93)
3.94)
3.95)
3.96)
3.97)
3.98)
3.99)
3.100)
3.101)
3.102)
3.103)
TODO: when you see something like -x^n, you evaluate it as -(x * x * x * ...). WHY? this of it as -1*x^n -- do the exponent first than the multiplication.
3.104)
3.105) 17 - 4(8 - 11) = 17 - 4(-3) = 17 - -12 = 29
3.106) 16 - 6(7 - 13) = 16 - 6(-6) = 16 - -36 = 52
3.107) 12(-9) / (-3)^2 = -108 / 9 = 12
3.108) 18(-4) / (-2)^3 = -72 / -8 = 9
3.109) -27 / 3 + (-5)(-6) = -27 / 3 + 30 = -9 + 30 = 21
3.110) -32 / 4 + (-2)(-7) = -32 / 4 + 14 = -16 + 14 = -2
3.111)
3.112)
3.113)
3.114)
3.115) -5 * 12 = 60
3.116) 8 * -13 = -104
3.117) -63 / -9 = 7
3.118) -72 / -9 = 8
EXERCISE
3.4.211) -4 * 8 = -32
3.4.212) -3 * 9 = -27
3.4.213) -5(7) = -35
3.4.214) -8(6) = -48
3.4.215) -18(-2) = 36
3.4.216) -10(-6) = 60
3.4.217) 9(-7) = -63
3.4.218) 13(-5) = -65
3.4.219) -1(6) = -6
3.4.220) -1(3) = -3
3.4.221) -1(-14) = 14
3.4.222) -1(-19) = 19
3.4.223) -24 / 6 = -4
3.4.224) -28 / 7 = -4
3.4.225) 56 / -7 = -8
3.4.226) 35 / -7 = -5
3.4.227) -52 / -4 = 13
3.4.228) -84 / -6 = 14
3.4.229) -180 / 15 = -11
3.4.230) -192 / 12 = -16
3.4.231) 49 / -1 = -49
3.4.232) 62 / -1 = -62
3.4.233)
3.4.234)
3.4.235)
3.4.236)
3.4.237)
3.4.238)
3.4.239)
3.4.240)
3.4.241)
3.4.242)
3.4.243)
3.4.244)
3.4.245)
3.4.246)
3.4.247)
3.4.248)
3.4.249)
3.4.250)
3.4.251)
3.4.252)
3.4.253)
3.4.254)
3.4.255)
3.4.256)
3.4.257)
3.4.258)
3.4.259)
3.4.260)
3.4.261)
3.4.262)
3.4.263)
3.4.264)
3.4.265)
3.4.266)
3.4.267)
3.4.268)
3.4.269)
3.4.270)
3.4.271) -3 * 5 = -15
3.4.272) -4 * 16 = -64
3.4.273) -60 / -20 = 3
3.4.274) -40 / - 20 = 2
3.4.275) -6 / (a + b)
3.4.276) -7 / (m + n)
3.4.277) -10 * (p - q)
3.4.278) -13 * (c - d)
3.4.279) (x - 12) * 300
3.4.280) (x - 3) * 8
3.4.281) if the signs are the same, the product has a positive sign. otherwise, product has negative sign
3.4.282) if the signs are the same, the quotient has a positive sign. otherwise, quotient has negative sign
3.4.283) you have to evaluate the exponent before the sign, because you have to think about -2 as -1 * 2, so the entire thing is really -1 * 2^4 because you evaluate exponents before multiplication
3.4.284) you have to evaluate the exponent before the sign, because you have to think about -4 as -1 * 4, so the entire thing is really -1 * 4^2 because you evaluate exponents before multiplication
TRY IT
3.119) 2x - 8 = -14
3.120) 2y + 3 = -11
3.121)
3.122)
3.123)
3.124)
3.125)
3.126)
3.127)
3.128)
3.129)
3.130)
3.131)
3.132)
3.133)
3.134)
3.135)
3.136)
EXERCISE
3.5.285) 4x - 2 = 6
3.5.286) 4y - 10 = -14
3.5.287) 9a + 27 = -63
3.5.288) 7c + 42 = -56
3.5.289)
3.5.290)
3.5.291)
3.5.292)
3.5.293)
3.5.294)
3.5.295)
3.5.296)
3.5.297)
3.5.298)
3.5.299)
3.5.300)
3.5.301)
3.5.302)
3.5.303)
3.5.304)
3.5.305)
3.5.306)
3.5.307)
3.5.308)
3.5.309)
3.5.310)
3.5.311)
3.5.312)
3.5.313)
3.5.314)
3.5.315)
3.5.316)
3.5.317)
3.5.318)
3.5.319)
3.5.320)
3.5.321)
3.5.322)
3.5.323)
3.5.324)
3.5.325)
3.5.326)
3.5.327)
3.5.328)
3.5.329)
3.5.330)
3.5.331)
3.5.332)
3.5.333)
3.5.334)
3.5.335)
3.5.336)
3.5.337)
3.5.338) -6n = -48, n = -8
3.5.339) -39 = u + 13, u = -52
3.5.340) -100 = v + 25, v = -125
3.5.341) 11r = -99, r = -9
3.5.342) 15s = -300, s = -20
3.5.343) 100 = 20d, d = 5
3.5.344) 250 = 25n, n = 10
3.5.345) -49 = x - 7, x = -42
3.5.346) 64 = y - 4, y = 68
3.5.347)
3.5.348)
3.4.349) sure -- it shows how the 15 needs to be grouped
3.4.350)
for the first one ... 1 enevlope + 4 dots is the same as 12 dots
for the second one, 4 envelopes is the same as 12 dots
3.5.351) the multiple of -3 needs to be removed from the the x to isolate it -- adding 3 doesn't do that
3.5.352) 4y = 40, the multiple of 5 needs to be removed from teh y to isolate it -- subtracting 4 doesn't do that
TRY IT
4.1)
4.2)
4.3) 6 slices of the 8 would be shaded -- it isn't easy to draw using text
4.4) 2 bars of the 5 would be shaded -- it isn't easy to draw using text
4.5) can't do fraction circles because drawing circles isn't easy using text
+-----+-----+-----+
| 1/3 | 1/3 | 1/3 |
+-----+-----+-----+
4.6) can't do fraction circles because drawing circles isn't easy using text
+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+-----+-----+-----+-----+-----+
4.7) 1 2/3 (can't do fraction circles because drawing circles isn't easy using text)
4.8) 1 1 1/2 (can't do fraction circles because drawing circles isn't easy using text)
4.9) 5/3, 1 2/3
4.10) 13/8, 1 5/8
4.11)
+-----+-----+-----+-----+-----+-----+ +-----+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | | 1/6 |
+-----+-----+-----+-----+-----+-----+ +-----+
4.12)
+-----+-----+-----+-----+-----+ +-----+
| 1/5 | 1/5 | 1/5 | 1/5 | 1/5 | | 1/5 |
+-----+-----+-----+-----+-----+ +-----+
4.13)
+-----+-----+-----+-----+-----+-----+-----+ +-----+-----+
| 1/7 | 1/7 | 1/7 | 1/7 | 1/7 | 1/7 | 1/7 | | 1/7 | 1/7 |
+-----+-----+-----+-----+-----+-----+-----+ +-----+-----+
1 2/7
4.14)
+-----+-----+-----+-----+ +-----+-----+-----+
| 1/4 | 1/4 | 1/4 | 1/4 | | 1/4 | 1/4 | 1/4 |
+-----+-----+-----+-----+ +-----+-----+-----+
1 3/4
4.15) 11/8
4.16) 11/6
4.17) 1 6/7
4.18) 1 5/9
4.19) 3 2/7
4.20) 4 4/11
4.21) 26/7
4.22) 23/8
4.23) 50/11
4.24) 34/3
4.25)
+-----------+-----------+-----------+-----------+
| 1/4 | 1/4 | 1/4 | 1/4 |
+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+-----+-----+-----+-----+-----+
2/8 = 1/4
4.26)
+--------------------+--------------------+--------------------+--------------------+
| 1/4 | 1/4 | 1/4 | 1/4 |
+------+------+------+------+------+------+------+------+------+------+------+------+
| 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 |
+------+------+------+------+------+------+------+------+------+------+------+------+
3/12 = 1/4
4.27)
4.28)
4.29) 18/21
4.30) 30/100
4.31) can't do this using text
4.32) can't do this using text
4.33) can't do this using text
4.34) can't do this using text
4.35)
4.36)
EXERCISE
4.1.1)
4.1.2)
4.1.3)
+--------+
| filled |
+--------+
| |
+--------+
4.1.4)
+--------+
| filled |
+--------+
| |
+--------+
| |
+--------+
4.1.5)
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| |
+--------+
4.1.6)
+--------+
| filled |
+--------+
| filled |
+--------+
| |
+--------+
| |
+--------+
| |
+--------+
4.1.7)
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| |
+--------+
4.1.8)
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| |
+--------+
4.1.9)
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| |
+--------+
| |
+--------+
| |
+--------+
4.1.10)
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| filled |
+--------+
| |
+--------+
| |
+--------+
| |
+--------+
4.1.11) 1 1/2 (can't draw circles easily in text)
4.1.12) 1 (can't draw circles easily in text)
4.1.13) 1 1/6 (can't draw circles easily in text)
4.1.14) 1 1/3 (can't draw circles easily in text)
4.1.15) 1 2/5 (can't draw circles easily in text)
4.1.16) 1 3/4 (can't draw circles easily in text)
4.1.17)
4.1.18)
4.1.19)
4.1.20) 1 (can't draw circles easily in text)
4.1.21) 1 (can't draw circles easily in text)
4.1.22) 1 3/4 (can't draw circles easily in text)
4.1.23) 1 2/3 (can't draw circles easily in text)
4.1.24) 1 5/6 (can't draw circles easily in text)
4.1.25) 1 5/8 (can't draw circles easily in text)
4.1.26) 3 1/3 (can't draw circles easily in text)
4.1.27) 2 1/4 (can't draw circles easily in text)
4.1.28) 1 1/2
4.1.29) 1 2/3
4.1.30) 2 3/4
4.1.31) 2 3/5
4.1.32) 4 1/6
4.1.33) 3 1/9
4.1.34) 3 3/13
4.1.35) 3 2/15
4.1.36) 5/3
4.1.37) 7/5
4.1.38) 9/4
4.1.39) 17/6
4.1.40) 25/9
4.1.41) 19/5
4.1.42) 25/7
4.1.43) 32/9
4.1.44)
+-----------+-----------+-----------+
| 1/3 | 1/3 | 1/3 |
+-----+-----+-----+-----+-----+-----+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
+-----+-----+-----+-----+-----+-----+
2/6
4.1.45)
+---------------------------+---------------------------+---------------------------+
| 1/3 | 1/3 | 1/3 |
+------+------+------+------+------+------+------+------+------+------+------+------+
| 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 |
+------+------+------+------+------+------+------+------+------+------+------+------+
4/12
4.1.46)
+-----------+-----------+-----------+-----------+
| 1/4 | 1/4 | 1/4 | 1/4 |
+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+-----+-----+-----+-----+-----+
6/8
4.1.47)
+--------------------+--------------------+--------------------+--------------------+
| 1/4 | 1/4 | 1/4 | 1/4 |
+------+------+------+------+------+------+------+------+------+------+------+------+
| 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 |
+------+------+------+------+------+------+------+------+------+------+------+------+
9/12
4.1.48)
+-----------+-----------+-----------+
| 1/2 | 1/2 | 1/2 |
+-----+-----+-----+-----+-----+-----+
| 1/4 | 1/4 | 1/4 | 1/4 | 1/4 | 1/4 |
+-----+-----+-----+-----+-----+-----+
6/4
4.1.49)
+-----------------+-----------------+-----------------+
| 1/2 | 1/2 | 1/2 |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
9/6
4.1.50)
4.1.51)
4.1.52)
4.1.53)
4.1.54)
4.1.55)
4.1.56) can't do this using text
4.1.57) can't do this using text
4.1.58) can't do this using text
4.1.59) can't do this using text
4.1.60) can't do this using text
4.1.61) can't do this using text
4.1.62) can't do this using text
4.1.63) can't do this using text
4.1.64) -1 < -1/4
4.1.65) -1 < -1/3
4.1.66) -2 1/2 > -3
4.1.67) -1 3/4 > -2
4.1.68) -5/12 > -7/12
4.1.69) -9/10 < -3/10
4.1.70) -3 < -13/5
4.1.71) -4 < -23/6
4.1.72) 1/5 count has 5 steps in a count, 1/4 count has 4 steps in a count
4.1.73)
4.1.74)
1/2 walnut per pan, 5 pans
4.1.75) baking cookies
4.1.76) turn it into a mixed number, the dot dsits between the whole and the next number
so 21/4 = 5 1/4, the dot sits between 5 and 6 -- just past 5, it's a quarter of the way between 5 and 6
TRY IT
4.37)
4.38)
4.39)
4.40)
4.41)
4.42)
4.43) 69 / 120
69
120
23 / 40
4.44) 120 / 192
120
192
60 / 96
4.45)
4.46)
4.47)
cut here
|
v
+---------------+---------------+---------------+
| 1/5 | 1/5 | 1/5 |
+-------+-------+-------+-------+-------+-------+
| 1/10 | 1/10 | 1/10 | 1/10 | 1/10 | 1/10 |
+-------+-------+-------+-------+-------+-------+
3/10
4.48)
cut here
|
v
+---------------+---------------+---------------+---------------+---------------+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 |
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
5/12
4.49)
4.50)
4.51)
4.52)
4.53)
4.54)
4.55)
4.56)
4.57)
4.58)
4.59)
| Number | Opposite | Absolute Value | Reciprocal |
|---|---|---|---|
| -5/8 | 5/8 | 5/8 | -8/5 |
| 1/4 | -1/4 | 1/4 | 4/1 |
| 8/3 | -8/3 | 8/3 | 3/8 |
| -8 | 8 | 8 | -1/8 |
4.60)
| Number | Opposite | Absolute Value | Reciprocal |
|---|---|---|---|
| -4/7 | 4/7 | 4/7 | -7/4 |
| 1/8 | -1/8 | 1/8 | 8/1 |
| 9/4 | -9/4 | 9/4 | 4/9 |
| -1 | 1 | 1 | -1 |
4.61) 1/3 / 1/6
how many 1/6s are there in 1/3?
1/3 can be re-written as 2/6
+---------------+
| 1/3 |
+-------+-------+
| 1/6 | 1/6 |
+-------+-------+
4.62)
+---------------+
| 1/2 |
+-------+-------+
| 1/4 | 1/4 |
+-------+-------+
4.63)
+-----------------------------------------------+
| 2 |
+-------+-------+-------+-------+-------+-------+
| 1/3 | 1/3 | 1/3 | 1/3 | 1/3 | 1/3 |
+-------+-------+-------+-------+-------+-------+
4.64)
+-----------------------------------------------+
| 3 |
+-------+-------+-------+-------+-------+-------+
| 1/2 | 1/2 | 1/2 | 1/2 | 1/2 | 1/2 |
+-------+-------+-------+-------+-------+-------+
4.65)
4.66)
4.67)
4.68)
4.69)
4.70)
4.71)
4.72)
EXERCISE
4.2.77) 7/21 = 1/3
4.2.78) 8/24 = 1/3
4.2.79) 15/20 = 3/4
4.2.80) 12/18 = 6/9 = 2/3
4.2.81) -40/88 = -20/44 = -10/22 = -5/11
4.2.82) -63/99 = -21/33 = -7/11
4.2.83) -108/63 = -36/21 = -12/7
4.2.84) -104/48 = -52/24 = -26/12 = -13/6
4.2.85) 120/252 = 60/126 = 30/63 = 10/21
4.2.86) 182/294
182
294
common factors: 2, 7
182/294 = 91/147 = 13/21
4.2.87) -168/192 = -84/96 = -28/32 = -14/16 = -7/8
4.2.88) -140/224 = -70/112 = -10/16 = -5/8
4.2.89) 11x/11y = x/y
4.2.90) 15a/15b = a/b
4.2.91) -3x/12y = -x/4y
4.2.92) -4x/32y = -x/8y
4.2.93) -14x^2/21y = -2x^2/3y
4.2.94) 24a/32b^2 = 12a/16b^2 = 6a/8b^2 = 3a/4b^2
4.2.95)
cut here
|
v
+-----+-----+
| 1/3 | 1/3 |
+-----+-----+
1/3
4.2.96)
cut here
|
v
+-------------+-------------+-------------+-------------+-------------+
| 1/8 | 1/8 | 1/8 | 1/8 | 1/8 |
+------+------+------+------+------+------+------+------+------+------+
| 1/16 | 1/16 | 1/16 | 1/16 | 1/16 | 1/16 | 1/16 | 1/16 | 1/16 | 1/16 |
+------+------+------+------+------+------+------+------+------+------+
5/16
4.2.97)
cut here
|
v
+-------------+-------------+-------------+-------------+-------------+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
+------+------+------+------+------+------+------+------+------+------+
| 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 | 1/12 |
+------+------+------+------+------+------+------+------+------+------+
3/12
4.2.98)
cut here
|
v
+--------------------+--------------------+
| 1/5 | 1/5 |
+------+------+------+------+------+------+
| 1/15 | 1/15 | 1/15 | 1/15 | 1/15 | 1/15 |
+------+------+------+------+------+------+
2/15
4.2.99) 2/15
4.2.100) 3/16
4.2.101) 27/40
4.2.102) 8/35
4.2.103) 6/24
4.2.104) 12/36 = 6/18 = 3/9 = 1/3
4.2.105) -15/90 = -3/18 = -1/6
4.2.106) 12/120 = 1/10
4.2.107) -56/252 = -28/126 = -14/63
4.2.108) -40/180 = -20/90 = -2/9
4.2.109) -126/300 = -63/150 = -21/50
4.2.110) -175/330 = -35/66
4.2.111) 2772/7560 = 1386/3780 = 693/1890 = 231/630 = 77/210 = 11/30 =
4.2.112) 1320/5280 = 132/528 = 44/176 = 22/88 = 2/8 = 1/4
4.2.113) 20/11
4.2.114) 120/3 = 40/1
4.2.115) 63n/7 = 9n/1
4.2.116) 150m/6 = 75m/3 = 25m/1
4.2.117) 28p/4 = 14p/2 = 7p/1
4.2.118) 51q/3 = 17q/1
4.2.119) -136/4 = -68/2 = -34/1
4.2.120) -210/5 = -42/1
4.2.121) 3/8
4.2.122) 6/7
4.2.123) 8/21
4.2.124) 16/25
4.2.125) 1296/625 (cannot reduce any further, see factor trees for numerator and denominator below)
1296
625
4.2.126) 256/2401 (cannot reduce any further, see factor trees for numerator and denominator below)
256
2401
4.2.127) 4/3
4.2.128) 3/2
4.2.129) -17/5
4.2.130) -19/6
4.2.131) 11/8
4.2.132) -1/3
4.2.133)-1/19
4.2.134) -1/1
4.2.135) 1/1
4.2.136)
| Number | Opposite | Absolute Value | Reciprocal |
|---|---|---|---|
| -7/11 | 7/11 | 7/11 | -11/7 |
| 4/5 | -4/5 | 4/5 | 5/4 |
| 10/7 | -10/7 | 10/7 | 7/10 |
| -8 | 8 | 8 | -1/8 |
4.2.137)
| Number | Opposite | Absolute Value | Reciprocal |
|---|---|---|---|
| -3/13 | 3/13 | 3/13 | 13/3 |
| 9/14 | -9/14 | 9/14 | -14/9 |
| 15/7 | -15/7 | 15/7 | -7/15 |
| -9 | 9 | 9 | 1/9 |
4.2.138)
+-----------------------+
| 1/2 |
+-----------+-----------+
| 1/4 | 1/4 |
+-----------+-----------+
there are 2 instances of 1/4 in 1/2
4.2.139)
+-----------------------+
| 1/2 |
+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+-----+
there are 4 instances of 1/8 in 1/2
4.2.140)
+-----------------------------------------------------------+
| 10 |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/5 | 1/5 | 1/5 | 1/5 | 1/5 | 1/5 | 1/5 | 1/5 | 1/5 | 1/5 |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
there are 10 instances of 1/5 in 2
4.2.141)
+-----------------------------------------------------------------------+
| 3 |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/4 | 1/4 | 1/4 | 1/4 | 1/4 | 1/4 | 1/4 | 1/4 | 1/4 | 1/4 | 1/4 | 1/4 |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
there are 12 instances of 1/4 in 3
4.2.142)
4.2.143)
4.2.144)
4.2.145)
4.2.146)
4.2.147)
4.2.148)
4.2.149)
4.2.150)
4.2.151)
4.2.152)
4.2.153)
4.2.154)
4.2.155)
4.2.156)
4.2.157)
4.2.158)
4.2.159)
4.2.160)
4.2.161)
4.2.162)
4.2.163)
4.2.164)
4.2.165)
4.2.166)
4.2.167)
4.2.168)
a) 3/4 * 2/1 = 6/4 = 3/2 = 1 1/2
b)
+-----------------+
| 3/2 |
+-----+-----+-----+
| 1/2 | 1/2 | 1/2 |
+-----+-----+-----+
+-----------------+
| 3/2 |
+-----------+-----+
| 1 | 1/2 |
+-----------+-----+
4.2.169)
4 pan, 2/3 cups of condensed milk each
a) 2/3 * 4/1 = 8/3 = 2 2/3
b)
+-----------------------------------------------+
| 8/3 |
+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/3 | 1/3 | 1/3 | 1/3 | 1/3 | 1/3 | 1/3 | 1/3 |
+-----+-----+-----+-----+-----+-----+-----+-----+
+-----------------------------------------------+
| 8/3 |
+-----------------+-----------------+-----+-----+
| 1 | 1 | 1/3 | 1/3 |
+-----------------+-----------------+-----+-----+
4.2.170)
4.2.171)
4.2.172) swap the num and denom
4.2.173) swap the num and denom
4.2.174) the number of slices doesn't matter as he would be getting the same amount of pizza either way
4.2.175) you have half a meter of ribbon remaining and you want to make sure that you only use 2/3rds of it -- that would be 1/3 meter
TRY IT
4.73)
4.74)
4.75)
4.76)
4.77)
4.78)
4.79)
4.80)
4.81) 9s/14
4.82) 5y/6
4.83) (a-b)/cd
4.84) (p+q)/r
4.85)
4.86)
4.87)
4.88)
4.89)
4.90)
4.91)
4.92)
4.93) -(3/5), 3/-5
4.94) -2/-7. 2/7
4.95) 10/8 = 5/4
4.96) -2/6 = -1/3
4.97) -9/12 = -3/4
4.98) -20/30 = -2/3
4.99) 16/72 = 8/36 = 4/18 = 2/9
4.100) 64/40 = 32/20 = 16/10 = 8/5
4.101) -28/7 = -4/1
4.102) -34/-17 = -2/1
EXERCISE
4.3.176)
4.3.177)
4.3.178)
4.3.179)
4.3.180)
4.3.181)
4.3.182)
4.3.183)
4.3.184)
4.3.185)
4.3.186)
4.3.187)
4.3.188)
4.3.189)
4.3.190)
4.3.191)
4.3.192) 5u/11
4.3.193) 7v/13
4.3.194) p/q
4.3.195) a/b
4.3.196) r/s+10
4.3.197) a/3-b
4.3.198)
4.3.199)
4.3.200)
4.3.201)
4.3.202)
4.3.203)
4.3.204)
4.3.205)
4.3.206)
4.3.207)
4.3.208)
4.3.209)
4.3.210)
4.3.211)
4.3.212)
4.3.213)
4.3.214) (-5)/11, -5/11
4.3.215) (-4)/9, -4/9
4.3.216) (-11)/3, 11/(-3)
4.3.217) 13/(-6), (-13)/6
4.3.218) 15/8
4.3.219) 12/7
4.3.220) 25/10
4.3.221) 15/6
4.3.222)
4.3.223)
4.3.224) 0/12
4.3.225)
4.3.226)
4.3.227)
4.3.228)
4.3.229)
4.3.230)
4.3.231)
4.3.232)
4.3.233)
4.3.234)
4.3.235)
4.3.236)
4.3.237)
4.3.238)
4.3.239)
4.3.240)
4.3.241)
4.3.242)
4.3.243)
4.3.244)
why include questions with decimal numbers if you haven't discussed decimal numbers at all?
4.3.245)
why include questions with decimal numbers if you haven't discussed decimal numbers at all?
4.3.246)
4.3.247)
4.3.248)
a) 9/4 * 2/1 = 18/4 = 4 2/4 = 4 1/2
b)
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/2 | 1/2 | 1/2 | 1/2 | 1/2 | 1/2 | 1/2 | 1/2 | 1/2 |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 1 | 1 | 1/2 |
+-----------------------+-----------------------+-----+
4.3.249)
4.3.250) swap the numerator and denominator
4.3.251) most straight forward way is to get both numbers as proper/improper fractions and multiply.
4.3.252) he's multiplying the wholes and then multiplying the fractions, which is not what you should be doing. convert both numbers into fractions first and then multiply.
4.3.253) fractions represent division, when only one of the operands into a division operation is negative, the result is negative
TRY IT
4.103)
+-----+ +-----+-----+-----+-----+
| 1/8 | | 1/8 | 1/8 | 1/8 | 1/8 |
+-----+ +-----+-----+-----+-----+
combine to
+-----+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+-----+-----+
4.104)
+-----+ +-----+-----+-----+-----+
| 1/6 | | 1/6 | 1/6 | 1/6 | 1/6 |
+-----+ +-----+-----+-----+-----+
combine to
+-----+-----+-----+-----+-----+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
+-----+-----+-----+-----+-----+
4.105) 5/6
4.106) 10/10
4.107) (x+3)/4
4.108) (y+5)/8
4.109) -15/d
4.110) -15/m
4.111) 9p/8
4.112) 9q/5
4.113) -10/15 = -2/3
4.114) -14/21 = -2/3
4.115) 3/8
4.116) 1/6
4.117) 12/28 = 6/14 = 3/7
4.118) 16/32 = 1/2
4.119) (x-2)/7
4.120) (y-13)/14
4.121) -2/x
4.122) -12/a
4.123) -5/5 = -1
4.124) -6/9 = -2/3
EXERCISE
4.4.254)
+-----+-----+ +-----+
| 1/5 | 1/5 | | 1/5 |
+-----+-----+ +-----+
combine to
+-----+-----+-----+
| 1/5 | 1/5 | 1/5 |
+-----+-----+-----+
4.4.255)
+------+------+------+ +------+------+------+------+
| 1/10 | 1/10 | 1/10 | | 1/10 | 1/10 | 1/10 | 1/10 |
+------+------+------+ +------+------+------+------+
combine to
+------+------+------+------+------+------+------+
| 1/10 | 1/10 | 1/10 | 1/10 | 1/10 | 1/10 | 1/10 |
+------+------+------+------+------+------+------+
4.4.256)
+-----+ +-----+-----+-----+
| 1/6 | | 1/6 | 1/6 | 1/6 |
+-----+ +-----+-----+-----+
combine to
+-----+-----+-----+-----+
| 1/6 | 1/6 | 1/6 | 1/6 |
+-----+-----+-----+-----+
4.4.257)
+-----+-----+-----+ +-----+-----+-----+
| 1/8 | 1/8 | 1/8 | | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+ +-----+-----+-----+
combine to
+-----+-----+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+-----+-----+-----+
4.4.258) 5/9
4.4.259) 7/9
4.4.260) 13/13
4.4.261) 16/15
4.4.262) (x+3)/4
4.4.263) (y+2)/3
4.4.264) 16/p
4.4.265) 14/q
4.4.266) 11b/9
4.4.267) 9a/7
4.4.268) -9y/8
4.4.269) -4x/5
4.4.270) -4/8
4.4.271) -6/8
4.4.272) -10/16
4.4.273) -14/16
4.4.274) 7/17
4.4.275) 8/19
4.4.276) -16/13
4.4.277) -13/12
4.4.278)
+-----+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+-----+-----+
slice off
+-----+-----+
| 1/8 | 1/8 |
+-----+-----+
to become
+-----+-----+-----+
| 1/8 | 1/8 | 1/8 |
+-----+-----+-----+
4.4.279)
+-----+-----+-----+-----+-----+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
+-----+-----+-----+-----+-----+
slice off
+-----+-----+
| 1/6 | 1/6 |
+-----+-----+
to become
+-----+-----+-----+
| 1/6 | 1/6 | 1/6 |
+-----+-----+-----+
4.4.280) 3/5
4.4.281) 1/5
4.4.282) 4/15
4.4.283) 5/13
4.4.284) 6/12
4.4.285) 2/12
4.4.286) -15/21
4.4.287) -24/9
4.4.288) (y-9)/17
4.4.289) (x-8)/19
4.4.290) (5y-7)/8
4.4.291) (11z-8)/13
4.4.292) -5/d
4.4.293) -14/c
4.4.294) -38/u
4.4.295) -45/v
4.4.296) c/7
4.4.297) 3d/11
4.4.298) -9r/13
4.4.299) -14s/3
4.4.300) 1/5
4.4.301) 2/7
4.4.302)-2/9
4.4.303) -3/11
4.4.304)
4.4.305)
4.4.306) (n-4)/5
4.4.307) (6-s)/11
4.4.308) -5/24
4.4.309) -4/18 = -2/9
4.4.310)
4.4.311)
4.4.312) 9/10
4.4.313) 2/8
4.4.314) 1/16, 1/8, 3/16, 1/4, 5/16, 8/8, 7/16, 1/2, 9/16, 5/8
4.4.315) no -- the number of slices is greater than 1 whole pizza
TRY IT
4.125)
12
15
2 3 3
| 3 | 5
| | | |
v v v v
2 3 3 5 = 90
4.126)
15
5
3 5
| 5
| |
v v
3 5 = 15
4.127)
24
32
2 2 2 3
2 2 2 2 2 |
| | | | | |
v v v v v v
2 2 2 2 2 3 = 96
4.128)
28
32
2 2 7
2 2 2 2 2 |
| | | | | |
v v v v v v
2 2 2 2 2 7 = 224
4.129)
9/12, 10,12
4.130)
-35/60, 44/60
4.131)
52/96, 51/96
4.132)
72/224, 189/224
4.133) 3/12 + 4/12 = 7/12
4.134) 5/10 + 2/10 = 7/10
4.135) 4/8 - -1/8 = 5/8
4.136) 2/6 - -1/6 = 3/6
4.137)
12
15
2 2 3
| | 3 5
| | | |
v v v v
2 2 3 5 = 60
60/12=5
60/15=4
35/60 + 44/60 = 79/60
4.138)
15
20
3 5
2 2 | 5
| | | |
v v v v
2 2 3 5 = 60
60/15 = 4
60/20 = 3
52/60 + 51/60 = 103/60
4.139) 13/24 - 17/32
24
32
+-+-- 2*2 missing
| |
v v
2 2 2 3
2 2 2 2 2
^
|
+-- 3 missing
52/96 - 51/96 = 1/96
4.140) 21/32 - 9/28
32
28
+-- 7 missing
|
v
2 2 2 2 2
2 2 7
^ ^ ^
| | |
+-+-+-- 2*2*2 missing
147/224 - 72/224 = 75/224
4.141) -13/42 + 17/35
42
35
+-- missing 5
|
v
2 3 7
5 7
^ ^
| |
+-+-- 2 * 3 missing
-65/210 + 102/210 = 37/210
4.142) -19/24 + 17/32
24
32
+-+-- 2*2 missing
| |
v v
2 2 2 3
2 2 2 2 2
^
|
+-- 3 missing
-76/96 + 51/96 = -25/96
4.143) y/6 + 7/9
6
9
+-- 3 missing
|
v
2 3
3 3
^
|
+-- 2 missing
y/6 * 3/3 = 3y/18 7/9 * 2/2 = 14/18
3y/18 + 14/18 = (3y + 14)/18
4.144) x/6 + 7/15
6
15
+-- 5 missing
|
v
2 3
3 5
^
|
+-- 2 missing
x/6 * 5/5 = 5x/30 7/15 * 2/2 = 14/30
5x/30 + 14/30 = (5x+14)/30
4.145)
4.146)
4.147)
4.148)
4.149)
4.150)
4.151)
4.152)
4.153)
4.154)
4.155) -1/4 - 1/2 = -1/4 - 2/4 = -3/4
4.156) -5/2 - 3/8 = -20/8 - 3/8 = -23/8
4.157)
4.158)
4.159)
4.160)
EXERCISE
4.5.316) 12
4.5.317) 20
4.5.318) 24
4.5.319) 48
4.5.320) 210
2 3 5
2 3 7
4.5.321) 240
2 3 5
2 2 2 2 3
4.5.322) 280
5 7
2 2 2 7
4.5.323) 245
5 7
7 7
4.5.324) 12
3
2 3
2 2
4.5.325) 60
3
2 2
5
4.5.326) 4/12, 3/12
4.5.327) 5/20, 4/20
4.5.328) 10/24, 21/24
4.5.329) 14/24, 15/24
4.5.330) 39/48, -44/48
4.5.331) 33/48, -20/48
4.5.332) 3/12, 10/12, 9/12
4.5.333) 20/60, 45/60, 36/60
4.5.334) 8/15
4.5.335) 9/20
4.5.336) 9/14
4.5.337) 11/24
4.5.338) 4/9
4.5.339) 3/8
4.5.340) 3/10
4.5.341) 4/6 = 2/3
4.5.342) 8/12 + 9/12 = 17/12
4.5.343) 15/20 + 8/20 = 23/20
4.5.344) 14/24 + 15/24 = 29/24
4.5.345) 10/24 + 9/24 = 19/24
4.5.346) 7/12 - 9/16
12
16
+-+-- 2*2 missing
| |
v v
2 2 3
2 2 2 2
^
|
+-- 3 missing
(7/12 * 4/4) - (9/16 * 3/3) = 28/36 - 27/36 = 1/36
4.5.347) (7/16 * 3/3) - (5/12 * 4/4) = 21/36 - 20/36 = 1/36
4.5.348) 22/24 - 9/24 = 13/24
4.5.349) 15/24 - 14/24 = 1/24
4.5.350) 16/24 - 9/24 = 7/24
4.5.351) 10/12 - 9/12 = 1/12
4.5.352) -11/120 + 81/120 = 70/120 = 7/12
4.5.353) -27/60 + 34/60 = -7/60
4.5.354) -13/30 + 25/42 =
30
42
+-- 7 missing
|
v
2 3 5
2 3 7
^
|
+-- 5 missing
(-13/30 * 7/7) + (25/42 * 5/5) = -91/210 + 125/210
4.5.355) -23/30 + 5/48
30
48
+-+-+-- 2*2*2 missing
| | |
v v v
2 3 5
2 2 2 2 3
^
|
+-- 5 missing
(-23/30 * 8/8) + (5/48 * 5/5) = -184/240 + 25/240 = -159/240 = -53/80
4.5.356) -39/56 - 22/35
56
35
+-- 5 missing
|
v
2 2 2 7
5 7
^ ^ ^
| | |
+-+-+-- 2*2*2 missing
(-39/56 * 5/5) - (22/35 * 8/8) = -195/280 - 176/280 = -371/280 = 53/40
4.5.357) -33/49 - 18/35
49
35
+-- 5 missing
|
v
7 7
5 7
^
|
+-- 7 missing
(-33/49 * 5/5) - (18/35 * 7/7) = (-165/245) - (126/245) = -291/245
4.5.358) -8/12 - (-9/12) = 1/12
4.5.359) -15/20 - (-16/20) = 1/20
4.5.360) -45/80 - (-64/80) = 19/80
4.5.361) -14/40 - (-25/40) = 11/40
4.5.362) 8/8 + 7/8 = 15/8
4.5.363) 6/6 + 5/6 = 11/6
4.5.364) 9/9 - 5/9 = 4/9
4.5.365) 10/10 - 3/10 = 7/10
4.5.366) x/3 + 1/4 = 4x/12 + 3/12 = (4x+3)/12
4.5.367) y/2 + 2/3 = 3y/6 + 4/6 = (3y+4)/6
4.5.368) y/4 - 3/5 = 5y/20 - 12/20 = (5y-12)/20
4.5.369) x/5 - 1/4 = 4x/20 - 5/20 = (4x-5)/20
4.5.370)
4.5.371)
4.5.372)
4.5.373)
4.5.374)
4.5.375)
4.5.376)
4.5.377)
4.5.378) -3/8 * -10/3 = 30/24 = 15/12
4.5.379) -5/12 * -9/5 = 9/12
4.5.380) -3/8 + 5/12 = (-3/8 * 3/3) + (5/12 * 2/2) = -9/24 + 10/24 = 1/24
4.5.381) -1/8 + 7/12 = (-1/8 * 3/3) + (7/12 * 2/2) = -3/24 + 14/24 = 11/24
4.5.382) 5/6 - 1/9 = (5/6 * 3/3) - (1/9 * 2/2) = 15/18 - 2/18 = 13/18
4.5.383) 5/9 - 1/6 = (5/9 * 2/2) - (1/6 * 3/3) = 10/18 - 3/18 = 7/18
4.5.384) 3/8 * -10/21 = -30/168 = -15/84 = -5/28
4.5.385) 7/12 * -8/35 = -56/420 = -28/210 = -14/105 = -2/15
4.5.386) -7/15 - y/4 = (-7/15 * 4/4) - (y/4 * 15/15) = -28/60 - 15y/60 = (-28 - 15y)/60
4.5.387) -3/8 - x/11 = (-3/8 * 11/11) - (x/11 * 8/8) = -33/88 - 8x/88 = (-33 - 8x)/88
4.5.388) 11/12a * 9a/16 = 99a/192a = 33a/64a = 33/64
4.5.389) 10y/13 * 8/5y = 80y/65y = 16y/13y = 16/13
4.5.390)
4.5.391)
4.5.392)
4.5.393)
4.5.394)
4.5.395)
4.5.396)
4.5.397)
4.5.398)
4.5.399)
4.5.400)
4.5.401)
4.5.402)
4.5.403)
4.5.404)
4.5.405)
4.5.406)
4.5.407)
4.5.408)
4.5.409)
4.5.410)
4.5.411)
4.5.412)
4.5.413)
4.5.414)
4.5.415)
4.5.416)
4.5.417)
4.5.418)
4.5.419)
4.5.420)
4.5.421)
4.5.422)
4.5.423)
4.5.424)
4.5.425)
4.5.426)
4.5.427)
4.5.428)
4.5.429)
4.5.430)
4.5.431)
4.5.432) 3/16 + 3/8 = 3/16 + 6/16 = 9/16
4.5.433) 5/4 + 9/8 = 10/8 + 9/8 = 19/8
4.5.434) the pieces being added or subtracted need to be of equal size
4.5.435) list out the prime factors in each denom -- the missing elements is what you need to multiply each denom by to get them both to equal the lcd
TRY IT
4.161)
+-----------------------------+
| |
+-----------------------------+
+-----+-----+
| 1/5 | 1/5 |
+-----+-----+
--------------------------------------------------------------
+-----------------------------+
| |
+-----------------------------+
+-----------------------------+
| |
+-----------------------------+
+-----------------------------+
| |
+-----------------------------+
+-----+-----+-----+
| 1/5 | 1/5 | 1/5 |
+-----+-----+-----+
5
4.162)
+-----------------------------------+
| |
+-----------------------------------+
+-----------------------------------+
| |
+-----------------------------------+
+-----+
| 1/6 |
+-----+
--------------------------------------------------------------
+-----------------------------------+
| |
+-----------------------------------+
+-----------------------------------+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
+-----------------------------------+
+-----+-----+-----+-----+-----+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
+-----+-----+-----+-----+-----+
5
4.163)
+-----------------------------------+
| |
+-----------------------------------+
+-----------------------------------+
| |
+-----------------------------------+
+-----------------------------------+
| |
+-----------------------------------+
+-----------------------------------+
| |
+-----------------------------------+
+-----+-----+-----+-----+-----+-----+
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
+-----+-----+-----+-----+-----+-----+
+-----+-----+-----+-----+
| 1/6 | 1/6 | 1/6 | 1/6 |
+-----+-----+-----+-----+
4 4/6
4.164)
+-----------------------------------------------+
| |
+-----------------------------------------------+
+-----------------------------------------------+
| |
+-----------------------------------------------+
+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+-----+-----+-----+-----+-----+
+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 |
+-----+-----+-----+-----+
3 1/2
4.165) 5 6/7
4.166) 2 9/11
4.167) 16 1/2
4.168) 15 1/3
4.169) 9 1/3
4.170) 6 3/5
4.171)
+-----------------------+
| |
+-----------------------+
---------------------------------------
+-----+
| 1/4 |
+-----+
3/4
4.172)
+-----------------------------+
| |
+-----------------------------+
---------------------------------------
+-----+
| 1/5 |
+-----+
4/5
4.173)
+-----------------------------+
| |
+-----------------------------+
+-----------------------------+
| |
+-----------------------------+
---------------------------------------
+-----+
| 1/5 |
+-----+
1 4/5
4.174)
+-----------------+
| |
+-----------------+
+-----------------+
| |
+-----------------+
---------------------------------------
+-----+
| 1/3 |
+-----+
1 2/3
4.175) no more modeling after this point -- its too tedious to do in text
2/3
4.176) 3/4
4.177) 2/3
4.178) 2/5
4.179) 2 2/3
4.180) 1 5/7
4.181) 26/9
4.182) 12/7
4.183) 6 + 7/12
4.184) 12 3/10
4.185) 5 1/5
4.186) 1 11/12
4.187) -41/8
4.188) -757/63
EXERCISE
4.6.436) 4 2/5 (too tedious to draw model in text)
4.6.437) 3 2/3 (too tedious to draw model in text)
4.6.438) 3 2/8 (too tedious to draw model in text)
4.6.439) 3 4/6 (too tedious to draw model in text)
4.6.440) 11 2/3
4.6.441) 7 5/9
4.6.442) 14
4.6.443) 11
4.6.444) 10 3/5
4.6.445) 11
4.6.446) 15 1/5
4.6.447) 11 1/3
4.6.448) 1/3 (too tedious to draw model in text)
4.6.449) 1/2 (too tedious to draw model in text)
4.6.450) 1 4/8
4.6.451) 1 2/12
4.6.452) 4 8/20
4.6.453) 6 6/15
4.6.454) 3 6/7
4.6.455) 1 7/9
4.6.456) 6/8
4.6.457) 10/12
4.6.458)
4.6.459)
4.6.460)
4.6.461)
4.6.462)
4.6.463)
4.6.464)
4.6.465)
4.6.466)
4.6.467)
4.6.468) 6/7
4.6.469) 7/9
4.6.470)
4.6.471)
4.6.472)
4.6.473)
4.6.474)
4.6.475)
4.6.476)
4.6.477)
4.6.478)
4.6.479)
4.6.480)
4.6.481)
4.6.482)
4.6.483)
4.6.484)
4.6.485)
4.6.486)
4.6.487)
4.6.488)
4.6.489)
4.6.490) 3 4/8, 3 1/2
4.6.491) 1 -5/12
4.6.492) 5 1/2
4.6.493) 13 1/4
4.6.494)
+-----------------------------------------------+ | +-----------------------------------------------+
1 | | | | | 1
+-----------------------------------------------+ | +-----------------------------------------------+
+-----+-----+-----+-----+-----+ | +-----------------------------------------------+
5/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | | | | 1
+-----+-----+-----+-----+-----+ | +-----------------------------------------------+
| +-----+-----+-----+-----+-----+-----+-----+
| | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 7/8
| +-----+-----+-----+-----+-----+-----+-----+
| |
| |
+-----------------------------+----------------------------+
|
v
+-----------------------------------------------+
| | 1
+-----------------------------------------------+
+-----------------------------------------------+
| | 1
+-----------------------------------------------+
+-----------------------------------------------+
| | 1
+-----------------------------------------------+
+-----------------------------------------------+
| | 1
+-----------------------------------------------+
+-----+-----+-----+-----+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1/8 | 1
+-----+-----+-----+-----+-----+-----+-----+-----+
+-----+-----+-----+-----+
| 1/8 | 1/8 | 1/8 | 1/8 | 4/8
+-----+-----+-----+-----+
4.6.495)
4.6.496) mixed numbers are easier for a person to think about because the numbers they're dealing with are smaller, but i prefer leaving them as fractions, but i prefer leaving them as fractions because I don't have to think about it as whole + fraction, just fraction
4.6.497) mixed numbers are easier for a person to think about because the numbers they're dealing with are smaller, but i prefer leaving them as fractions because I don't have to think about it as whole + fraction, just fraction
TRY IT
4.189)
4.190)
4.191) y = 5/16 - 9/16 = -4/16
4.192) y = 4/15 - 8/15 = -4/15
4.193) a = -8/5 + 3/5 = -5/5
4.194) n = -9/7 + 3/7 = -6/7
4.195) u = -76/12
4.196) m = 92/8
4.197) f = -125
4.198) h = -243
4.199) c = 245
4.200) x = 131
4.201) y = -48
4.202) c = 23
4.203)
4.204)
4.205)
4.206)
4.207)
4.208)
4.209)
4.210)
4.211)
4.212)
4.213)
4.214)
4.215)
4.216)
EXERCISE
4.7.498)
4.7.499)
4.7.500)
4.7.501)
4.7.502)
4.7.503)
4.7.504)
4.7.505)
4.7.506)
4.7.507)
4.7.508)
4.7.509)
4.7.510)
4.7.511)
4.7.512)
4.7.513)
4.7.514)
4.7.515)
4.7.516)
4.7.517)
4.7.518)
4.7.519)
4.7.520)
4.7.521)
4.7.522)
4.7.523)
4.7.524)
4.7.525)
4.7.526)
4.7.527)
4.7.528)
4.7.529)
4.7.531)
4.7.532)
4.7.533)
4.7.534)
4.7.535)
4.7.536)
4.7.537)
4.7.538)
4.7.539)
4.7.540)
4.7.541)
4.7.542)
4.7.543)
4.7.544)
4.7.545)
4.7.546)
4.7.547)
4.7.548)
4.7.549)
4.7.550)
4.7.551)
4.7.552)
4.7.553)
4.7.554)
4.7.555)
4.7.556)
4.7.557)
4.7.558)
4.7.559)
4.7.560)
4.7.561)
4.7.562)
4.7.563)
4.7.564)
4.7.565)
4.7.566)
4.7.567)
4.7.568)
4.7.569)
4.7.570)
4.7.571)
4.7.572) no preference
4.7.573)
unsure where the number 16 came from. maybe he accidentally divided by 2
TRY IT
5.1)
5.2)
5.3) 13.68
5.4) 5.894
5.5) 0.058
5.6) 0.067
5.7)
5.8)
5.9)
|---|---|---|---|---|---|---|---|---|---|
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
^
5.10)
|---|---|---|---|---|---|---|---|---|---|
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
^
5.11)
|---|---|---|---|---|---|---|---|---|---|
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
^
0.63
5.12)
|---|---|---|---|---|---|---|---|---|---|
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
^
0.25
5.13)
5.14)
5.15) -0.3 > -0.5
5.16) -0.6 > -0.7
5.17) 1.05
5.18) 9.17
5.19)
5.20)
EXERCISE
5.1.1) five and five tenths
5.1.2) seven and eight tenths
5.1.3) five and one hundredths
5.1.4) fourteen and two hundredths
5.1.5) eight and seventy one hundredths
5.1.6) two and sixty four hundredths
5.1.7) two thousandths
5.1.8) five hundredths
5.1.9) three hundred eighty one thousandths
5.1.10) four hundred seventy nine thousandths
5.1.11) negative seventeen and nine tenths
5.1.12) negative thirty one and four tenths
5.1.13) 8.03
5.1.14) 9.07
5.1.15) 29.81
5.1.16) 61.74
5.1.17) 0.7
5.1.18) 0.6
5.1.19) 0.001
5.1.20) 0.009
5.1.21) 0.029
5.1.22) 0.035
5.1.23) -11.0009
5.1.24) -59.0002
5.1.25) 13.0395
5.1.26) 30.279
5.1.27) 1 99/100
5.1.28) 5 83/100
5.1.29) 15 7/10
5.1.30) 18 1/10
5.1.31) 239/1000
5.1.32) 373/1000
5.1.33) 13/100
5.1.34) 19/100
5.1.35) 11/1000
5.1.36) 49/1000
5.1.37) -7/100000
5.1.38) -3/100000
5.1.39) 64/10 or 6 4/10
5.1.40) 52/10 or 5 2/10
5.1.41) 705/100 or 7 5/100
5.1.42) 904/100 or 9 4/100
5.1.43) 4 6/1000
5.1.44) 2 8/1000
5.1.45) 10 25/100
5.1.46) 12 75/100
5.1.47) 1 324/1000
5.1.48) 2 482/1000
5.1.49) 12 125/1000
5.1.50) 20 375/1000
5.1.51)
|---|---|---|---|---|---|---|---|---|---|
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
^
5.1.52)
|---|---|---|---|---|---|---|---|---|---|
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
^
5.1.53)
|----|----|----|----|----|----|----|----|----|----|
-1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 -0
^
5.1.54)
|----|----|----|----|----|----|----|----|----|----|
-1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 -0
^
5.1.55)
...--|---|---|---|---|---|---|---|---|---|---|
3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0
^
5.1.56)
...|---|---|---|---|---|---|---|---|---|---|---|---|---|
2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0
^
5.1.57)
|----|----|----|----|----|----|----|----|----|----|
-3.0 -2.9 -2.8 -2.7 -2.6 -2.5 -2.4 -2.3 -2.2 -2.1 -2.0
^
5.1.58)
|----|----|----|----|----|----|----|----|----|----|
-2.0 -1.9 -1.8 -1.7 -1.6 -1.5 -1.4 -1.3 -1.2 -1.1 -1.0
^
5.1.59) 0.9 > 0.6
5.1.60) 0.7 < 0.8
5.1.61) 0.37 < 0.63
5.1.62) 0.86 > 0.69
5.1.63) 0.6 > 0.59
5.1.64) 0.27 < 0.3
5.1.65) 0.91 > 0.901
5.1.66) 0.415 > 0.41
5.1.67) 0.5 > −0.3
5.1.68) −0.1 > −0.4
5.1.69) −0.62 < −0.619
5.1.70) −7.31 < −7.3
5.1.71) 0.7
5.1.72) 0.5
5.1.73) 2.8
5.1.74) 4.6
5.1.75) 0.85
5.1.76) 0.76
5.1.77) 5.79
5.1.78) 3.63
5.1.79) 0.30 (can trim trialing 0)
5.1.80) 0.70 (can trim trialing 0)
5.1.81) 4.10 (can trim trialing 0)
5.1.82) 7.10 (can trim trialing 0)
5.1.83)
5.1.84)
5.1.85)
5.1.86)
5.1.87)
5.1.88)
5.1.89)
5.1.90)
5.1.91) money is an application of decimals
5.1.92) the and is the decimal point, stuff to the left is the whole while stuff to the right is the fractional.hundredths indicates that the fractional is a fraction that's some value over 100 (e.g. 9/100)
5.1.93) tim. he was faster because he took LESS time
5.1.94) what they're probably getting at is that if you wanted to buy just 1 postcard, it'd cost you 0.099 cents, but cents only go to the hundredths position. so if you were going to buy just 1 it'd likely be rounded up to 10 cents/
START BACK UP HERE START BACK UP HERE START BACK UP HERE START BACK UP HERE START BACK UP HERE START BACK UP HERE START BACK UP HERE START BACK UP HERE START BACK UP HERE START BACK UP HERE START BACK UP HERE START BACK UP HERE
START BACK UP HERE START BACK UP HERE START BACK UP HERE